一、配置文件.babelrc,存放在项目的根目录下
1)配置文件.babelrc
{ “presets": [ //presets字段设置转码规则 "es2015" ], "plugins": [] }
ES2015转码规则
npm install --save-dev babel-preset-es2015
2)命令行转码babel-cli安装在项目中
npm install --save-dev babel-cli
改写package.json
{
"devDependencies":{
"babel-cli": "^6.0.0"
},
"scrippts": {
"build": "babel src -d lib"
}
}
转码的时候执行 npm run build 命令
3)babel-poolyfill插件
npm install --save-dev babel-polyfill
import "babel-polyfill"
webpack.config.js中:
modeule.exports = {
entry: [‘babel-polyfill‘,‘./app/js‘]
}