Let Nodejs support ES6 's lexical----installation and use of Babel

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.