This article introduces the installation process of babel6.x ~ First of all, you can use babel to convert online

Then go to the topic:install babel (command line environment,For babel6.x)

1. Install babel-cli first (for using babel in the terminal)

Npm install -g babel-cli

2.Then install the babel-preset-es2015 plugin

Npm install --save babel-preset-es2015

Note:Babel5 version includes various conversion plugins by default.However, babel6.x related conversion plug-ins need to be downloaded by themselves,Such as transform-es2015-arrow-functions, transform-es2015-classes, etc., and the es2015 preset contains all plugins.If no plugins are installed,Then the conversion on the command line has no effect!

The --save parameter automatically updates the package.json file and writes in the dependencies

3. Enter on the command line:

Babel es6.js --presets es2015


Use "use strict";
[1, 2, 3] .map (function (x) {
Return x * x;

Note:The following parameter --presets es2015 means use this plugin to compile,If you don't write up conversion, it has no effect.

4. Plug-in configuration

write Writing this parameter every time is very troublesome,You can create a new configuration file .babelrc in the current directory.

But in windows system, right-click is not allowed to create a file without a file name,Can be created from the cmd command line:Open cmd in the current folder and type the command

Type nul>.babelrc

You can create files in the current directory.babelrc, then write to the file:


Then you can use babel es6.js to convert directly in the command line without adding parameters indicating the plugin used

Except establishment.Outside the babelrc file,Can also be configured in package.json,Just add the following attributes:


Attached babel common commands:

1.Convert es6.js file and output in the current named line program window

Babel es6.js

2. Convert es6.js to es5.js file (use -o or --out-file)

Babel es6.js -o es5.js

Babel es6.js --out-file es5.js

3. Monitor es6.js in real time and recompile as it changes (using -w or --watch)

Babel es6.js -w --out-file es5.js

Babel es6.js --watch --out-file es5.js

4, compile the entire src folder and output to the lib folder (use -d or --out-dir)

Babel src -d lib

Babel src --out-dir lib

5.Compile the entire src folder and output to a file

Babel src --out-file es5.js

6, directly enter the babel-node command, you can run es6 code directly in the command line


  • Previous The main character and related elements of the Android combat aircraft game (3)
  • Next Yii2 caching basic usage example