To use Babel, we need NODEJS environment and NPM, the main installation of Nodejs, NPM installed by default, now installed Nodejs is very simple, directly download the installation is good;
Installing Es-checker
Before using Babel, we need to check the current node support for ES6, we use the first Es-checker, the command line execution:
Npm-g Install Es-checker
Es-checker after installation, command line execution:es-checker , for example, my node environment version is v4.4.3, support 64% OH:
Installation of Babel
So let's install Babel, with Babel, and be able to use more advanced morphology!
Start by creating a new working directory and then create a package.json file with the internal content:
{ "name""my-project", " version""1.0.0", " devdependencies " : { }}
Then open cmd (command line) and execute the command installation BABEL-CLI in the working directory:
NPM --save-dev Install BABEL-CLI
Then install a global babel-cli:
Npm-g Install BABEL-CLI
Then in the working directory to create a file named . BABELRC , the contents of the file into the following (note the window system to create such a file system will prompt you:"must type the filename" , you can find another way to create, I created this file in the project directory of the development tool ):
{ "presets": [ "es2015" ], "plugins": [] }
Installing babel-preset-es2015
or the working directory, and then install babel-preset-es2015:
NPM Install--save-dev babel-preset-es2015
So far Babel has been installed:
Test ES6 Code
To create a test.js file, type the content:
let [a,b,c] = [1,2,3];console.log (a,b,c);
Execute in current directory:
Babel-node Test
The result should be this:
If you execute node test directly, my side will report an exception: syntaxerror:unexpected token [
Related
nodejs:https://nodejs.org/en/
Babel official website: https://babeljs.io/
NONO
Source: http://www.cnblogs.com/diligenceday/
QQ: 287101329
: 18101055830
Let Nodejs support ES6 's lexical----installation and use of Babel