The following are a few important npm packages. All Babel packages reside in a single repository on GitHub. Browsing their source code and their package.json files is instructive.

babel-core: the core compilation machinery and plugin infrastructure for Babel. You will rarely need to install this package, because other packages such as babel-cli have it as a dependency, meaning that it will be automatically installed when they are installed.

babel-cli: a command line interface to Babel. It includes the following commands:

babel-doctor detects common problems with your Babel installation.

babel transpiles files or stdin via Babel.

babel-node a version of the Node.js executable node that transpiles everything via Babel.

babel-external-helpers prints all of Babel’s helper functions (such as inherits for subclassing) to the console.

babel-register: lets you switch on Babel transpilation from within Node.js. After you do, all modules you require (minus code you want to ignore, e.g. packages installed via npm) are automatically transpiled.

Babel is often about compiling an input file, e.g. in the following two scenarios:

Compiling a file via the command line tool babel:

babel input-es6.js --out-file output-es5.js

Running a Node.js script written in ES6:

babel-node input-es6.js

The configuration data is an object of JSON data that is assembled from various sources (which are described later). Two configuration options have much influence on how the output is produced: plugins and presets.

If you want to compile something that isn’t part of the base syntax, you need both a syntax plugin and a corresponding transform plugin. However, each transform plugin that depends on a syntax plugin automatically activates that plugin.

Plugins are installed via npm. Their package names are their names plus the prefix babel-plugin-:

es2015-node5: Contains just those plugins that are needed to upgrade Node.js 5 to full ES6. Therefore, a lot less is transpiled than with the es2015 preset. Especially generators not being transpiled helps with debugging.

Presets are installed via npm. Their package names are their names plus the prefix babel-preset-. For example, this is how to install the preset es2015:

Property env of maps the names of environments ('development', 'production', etc.) to objects with more configuration data. If env exists, the object corresponding to the current environment is merged with the configuration data that has already been assembled. Consult the Babel documentation for more information on environments.

Property extends contains a path pointing to a file with more configuration data.

You can execute foo.js directly (if it is executable and starts with the right prolog):

cd tools/
./bin/foo.js

You can execute foo.js via npm run (as configured in scripts):

cd tools/
npm run foo arg1 arg2

If you install package tools globally, you get a command line command foo (as specified via bin).

If you install package tools locally, as a dependency of another package, you can execute foo via the scripts of that package, as if it was a globally installed command. That’s because npm adds the bin entries of all dependencies to the shell path before executing scripts (alas, not the bin entries in the same package.json).