Babel localization installation of front-end automation

Source: Internet
Author: User
Tags directory create

NPM Add Package.json

CD to project root directly call NPM init to create the Package.json file

Install Bebel locally (not a global installation, in which case the CMD command is not recognized by the Babel command):

Step Reference http://babeljs.io/

1. Installationnpm install --save-dev babel-cli babel-preset-env

2. Project root directory create. babelrc file

The format is as follows:

1 {2   "presets": ["env"]3 }

The array value following this Presets property represents the Babel component

Env says BABEL-PRESET-ENV

React says Babel-preset-react

Install local to project folder first NPM install--save-dev component Name

Manually added on the. babelrc file

Note: The locally installed Babel command is reduced by using NPM in the package script attribute in this example to view the Babel version, add attributes in the Package property scripts Getbabelversion

Package.json files are as follows

 { "name": "Project-blog"  "version": "0.0.1"  "description": "Folder to study sass NPM Yeoman"  "main": "Index.js"  "scripts" : {  "test": "Echo \" Error:no test specified\ "&& exit 1"  "Build": "Bab El src-d Lib "" Getbabelversion ":" Babel--version " ",  "author": "Tangerwei"  "license": "ISC"  "devdependencies" : { "babel-cli": "^ 6.18.0 " "babel-preset-env": "^1.1.6" ,  " Babel-preset-react ":" ^6.16.0 "}}  

Then run this directory (note to switch the execution path to the project root directory, the package is also in this directory) NPM run getbabelversion

Output: 6.18.0 (Babel-core 6.21.0)

Also note that the Devdependencies property is automatically updated when the Babel command is executed

This Babel plug-in installation is complete.

Append: Babel The default is to convert only the syntax, not the API, if it is in the ES6 in the api,es5 does not do? Using Babel-polyfill

Then, in the script header, add the following line of code.

Import ("Babel-polyfill"), or require ("Babel-polyfill");

Detailed checklist to view https://github.com/babel/babel/blob/master/packages/babel-plugin-transform-runtime/src/definitions.js files

NPM Run build compiles, but you also need to install a babel-preset-es2015

Babel installation use pit reference http://www.imooc.com/article/11157, very good article, but like me the novice needs to manually install the same time to see a few more times

Thinking:

It's true that NPM uses a fairly strong JS style and uses JSON as a configuration to be the same as the project.

NPM can invoke the local node plugin in Package.json, which can be done locally and directly js,css to native and low-version directions. And the release of the compiled version, the efficiency of programming has really improved greatly,

Not only that, even JS's lower version compatibility is better.

Babel localization installation of front-end automation

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.