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