JavaScript Learning Notes-ES6 learning (a) introduction and the Use of Babel

Source: Internet
Author: User

This digest from Nanyi Teacher's "ECMAScript 6", original address: http://es6.ruanyifeng.com/#docs/intro

ECMAScript 6 is a generic term that means the next-generation standard for JavaScript after the 5.1 version, covering the ES2015, ES2016, ES2017 and so on.

The Babel transcoding device is a widely used ES6 transcoding device that can convert ES6 to ES5.

configuration file:. BABELRC

Configuration file Basic format:

. BABELRC
{ "presets": [], "Plugins": [],}

Use Babel to install the rule set first, and then add it to the configuration file when you are finished installing it. The official rule set is as follows:

 # ES2015 transcoding rules  $ npm Install -- save-dev babel-preset-es2015  # react transcoding rules  $ npm Install -- save-dev babel-preset-react  Span style= "COLOR: #000000" ># ES7 transcoding rules for different stage syntax proposals (total 4 stages), choose a  npm install --  save-dev babel-preset-stage-0  $ npm Install -- save-dev babel-preset-stage-1  $ npm Install --  save-dev babel-preset-stage-2  $ npm Install -- save-dev babel-preset-stage-3  
. BABELRC
{ "presets": [ "es2015", "React", "stage-2" ], "Plugins": [] }

BABEL-CI Module

The Babel-ci module uses Babel on the command line, and the Babel command allows you to transcode the file directly, for the project to write it directly in Package.json, and then place the command in scripts.

The installation commands are as follows:

$ NPM Install--GLOBAL-CLI

The basic usage is as follows:

--out-file or---out----out-dir or---out----D lib-s

To load and use BABEL-CLI in a project:

--save-dev BABEL-CLI
// Package.json {  // ...  " Devdependencies ": {    " babel-cli ":" ^6.0.0 "  },  " Scripts ": {    " build " : "Babel src-d Lib"  },}

Babel-register Module

The Babel-register module overwrites the Require command, adds a hook to it, and thereafter, whenever you use require to load. js,. Jsx, and. es6 suffix files, you will first use Babel for transcoding:

$ NPM Install--save-dev Babel-register
Require ("Babel-register"); require ("./index.js");

Note: Babel-register will only transcode files that are loaded by the Require command, not the current file.

Babel can be used in a browser environment, but starting with version 6.0, the browser version is no longer directly available, but built with build tools.

Babel and Browserify are used together:

{     "browserify":   {         "transform": [["Babelify", {"presets": ["es2015"]}]     }} 

JavaScript Learning Notes-ES6 learning (a) introduction and the Use of Babel

Related Article

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.