ES6 Babel proper installation process _javascript techniques in JavaScript

Source: Internet
Author: User

This article describes the babel6.x installation process ~ First of all, you can use the Babel online conversion https://babeljs.io/repl/

Then go to the topic: Install Babel (command line environment, for babel6.x version)

1, first install BABEL-CLI (used in the terminal to use Babel)

NPM install-g BABEL-CLI

2, then install the babel-preset-es2015 plugin

NPM Install--save babel-preset-es2015

  Note: The BABEL5 version defaults to include a variety of conversion plug-ins, however babel6.x related conversion plug-ins need to download themselves, such as Transform-es2015-arrow-functions, transform-es2015-classes, and ES2015 Preset contains all the plug-ins. If you do not install any plug-ins, the conversion at the command line has no effect!

Where the--save parameter automatically updates the Package.json file and writes the dependencies

3, at the command line input:

Babel Es6.js--presets es2015

Output:

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

Note: The following parameter--presets es2015 indicates that the plug-in is compiled with no effect if the conversion is not written.

4, plug-in configuration

Write this argument every time it's a hassle. You can create a new profile in the current directory. BABELRC.

However, in Windows system, do not allow direct right to create files without file names, can be created through the cmd command line: Open cmd in the current folder and type the command

Type NUL>.BABELRC

You can create a file in the current directory. BABELRC, then write in the file:

{
"presets": [' es2015 ']

You can then convert directly to the command line using Babel es6.js without adding the parameters that indicate the plug-ins used

In addition to creating a. babelrc file, you can configure it in Package.json and add the following properties:

"Babel": {
"presets": ["es2015"]
}

Attached Babel common commands:

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

Babel Es6.js

2. Convert Es6.js to Es5.js file (using-O or--out-file)

Babel Es6.js-o Es5.js

Babel Es6.js--out-file Es5.js

3, real-time monitoring es6.js a change on the recompile (use-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 it 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, direct Input Babel-node command, you can run the ES6 code directly in the command line

Babel-node

The above is a small set to introduce the JavaScript ES6 Babel correct installation process, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.