首先安卓node.js,自动百度进行安装。
1.进入你的项目目录,打开命令窗口,安装babel
$ npm install --save-dev babel-core babel-preset-es2015 babel-preset-latest |
如果想快速安装,可以使用国内的资源
$ npm install --save-dev babel-core babel-preset-es2015 babel-preset-latest --registry https://registry.npm.taobao.org |
2.配置babel规则
在项目目录下新建.babelrc
{ "presets":["es2015","latest"], "plugins":[] } |
3.安装babel-ci模块,方便在命令行中使用babel。
$ npm install --global-cli |
4.使用
# 转码结果输出到标准输出 $ babel example.js
# 转码结果写入一个文件 # --out-file 或 -o 参数指定输出文件 $ babel example.js --out-file compiled.js # 或者 $ babel example.js -o compiled.js
# 整个目录转码 # --out-dir 或 -d 参数指定输出目录 $ babel src --out-dir lib # 或者 $ babel src -d lib # -s 参数生成source map文件 $ babel src -d lib -s |