项目初始化
npm init
项目中安装babel
npm install babel-cli --save-dev
安装相关babel插件
# babel-preset-xxxxxx
npm install babel-preset-es2015 --save-dev
改写package.json
# src:源目录;lib:目标目录
{
"devDependencies": {
"babel-cli": "^6.0.0"
},
"scripts": {
"build": "babel src -d lib"
},
}
根目录下配置文件.babelrc
# presets:转码规则,plugins:插件
{
"presets": [],
"plugins": []
}
转码,src转码后的文件在lib下
npm run build