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