Next: Plugins and Presets, Previous: Overview, Up: Babel [Index]
All the Babel modules you’ll need are published as separate npm packages scoped
under @babel
(since version 7). This modular design allows for various tools
each designed for a specific use case. Here we’ll look at @babel/core
and
@babel/cli
.
@babel/cli
is a tool that allows you to use babel from the terminal. Here’s
the installation command and a basic usage example:
npm install --save-dev @babel/core @babel/cli ./node_modules/.bin/babel src --out-dir lib
This will parse all the JavaScript files in the src
directory, apply any
transformations we have told it to, and output each file to the lib
directory. Since we haven’t told it to apply any transformations yet, the
output code will be identical to the input (exact code styling is not
preserved). We can specify what transformations we want by passing them as
options.
We used the ‘--out-dir’ option above. You can view the rest of the options accepted by the cli tool by running it with ‘--help’. But the most important to us right now are ‘--plugins’ and ‘--presets’.