[关闭]
@Tean 2017-11-19T14:25:09.000000Z 字数 692 阅读 661

babel入门

编译工具


安装

  1. npm install --save-dev babel-cli babel-preset-env

使用

创建文件.babelrc文件:

  1. {
  2. "presets": ["env"]
  3. }

1. 在package.json中配置

  1. "scripts": {
  2. "build": "babel index.js --out-file ./lib/index.js"
  3. }
  4. # --out-file 可简写为 -o

2. 在控制台直接输入

  1. ./node_modules/.bin/babel index.js -o ./lib/index.js

3. 常用编译命令

  1. # --out-file 或 -o 输出编辑结果到单个文件
  2. babel ./script.js -o ./script-com.js
  3. # --watch 或 -w 修改文件后编译文件(监听)
  4. babel ./script.js -o ./script-com.js -w
  5. # --source-maps 或 -s 生成source-map
  6. babel ./script.js -o ./script-com.js -s
  7. # --source-map inline 生成内联的source-map(不会单独生成文件)
  8. babel ./script.js -o ./script-com.js -s inline
  9. # --out-dir 或 -d 编译整个目录到目标目录
  10. babel ./src -d ./lib
  11. # 编译整个文件夹到单个文件中
  12. babel ./src -o ./lib/all.js
  13. # --ignore 忽略文件
  14. babel ./src -d ./lib --ignore jquery.min.js
  15. babel ./src -o ./all.js --ignore jquery.min.js
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注