The following are a few important npm packages.
Core Babel and access to Babel:
-
babel-core
: the core compilation machinery and plugin infrastructure for Babel. You will rarely need to install this package, because other packages such asbabel-cli
have it as a dependency, meaning that it will be automatically installed when they are installed. -
babel-cli
: a command line interface toBabel
. 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 executablenode
that transpiles everything via Babel.babel-external-helpers
prints all of Babel’s helper functions (such asinherits
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.
Complementary libraries:
-
babel-polyfill
: globally installs the ES6 standard library (new Array methods,Reflect
, etc.). This package is optional (there are other polyfills/shims or the JavaScript engine you are targeting may already provide everything you need). But if you do want to use it, you need to import it at least once in your app. Unless you are usingbabel-node
, which imports it while it is starting up. -
babel-plugin-external-helpers-2
: If this plugin is switched on, it does two things:- It puts all of Babel’s helper functions (such as
inherits
for subclassing) into an object stored in a global variable. - It calls those global functions from the code generated by Babel, instead of embedding the helpers in the code.
- It puts all of Babel’s helper functions (such as
-
babel-runtime
provides the services ofbabel-polyfill
andbabel-plugin-external-helpers-2
, but without using global variables (which is important for libraries). It is a modules that contains both the functionality of the ES6 standard library and the helpers mentioned in the previous item.- The plugin
transform-runtime
transforms Babel’s output so that operations use the modulebabel-runtime
instead of something global. This approach has limits – not everything global can be detected via static analysis and redirected to the module. The package of the plugin contains the filedefinitions.js
that lists what parts of the standard library are available.
- The plugin
All Babel packages reside in a single repository on GitHub. Browsing their source code and their package.json
files is instructive.