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-clihave 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-doctordetects common problems with your Babel installation.babeltranspiles files or stdin via Babel.babel-nodea version of the Node.js executablenodethat transpiles everything via Babel.babel-external-helpersprints all of Babel’s helper functions (such asinheritsfor 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
inheritsfor 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-runtimeprovides the services ofbabel-polyfillandbabel-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-runtimetransforms Babel’s output so that operations use the modulebabel-runtimeinstead 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.jsthat 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.