Home > Web Front-end > JS Tutorial > How is babel used in the project?

How is babel used in the project?

零下一度
Release: 2017-06-25 09:37:21
Original
1885 people have browsed it

1. Manually create the .babelrc file in the project

2. Install

$ npm install --save-dev babel-cli

# ES2015转码规则
$ npm install --save-dev babel-preset-es2015

# react转码规则
$ npm install --save-dev babel-preset-react

# ES7不同阶段语法提案的转码规则(共有4个阶段),选装一个
$ 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
Copy after login

3. Manually modify the .babelrc file

{"presets": [      "es2015",      "react",      "stage-2"],"plugins": []
  }
Copy after login

4. Modify the package.json file to achieve automatic transcoding. Please remove the comments when copying

{  "scripts": {"build": "babel src -d dist"  //这句表示把src目录下的文件自动转码到dist目录下,dist目录是自动创建的
  },  
}
Copy after login

4. Enter the following command on the command line to transcode

babel src -d dist
Copy after login

The above is the detailed content of How is babel used in the project?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template