多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
## babel-cli 常用命令 仍然使用上文中创建的 `src/main.js`进行测试 ```js let a = 0 ``` ### 控制台输出 ```bash $ babel src/main.js "use strict"; var a = 0; ``` ### 输出到文件 如果想输出编译结果到单个文件,你可以使用 `--out-file` 或 `-o` ```bash $ babel src/main.js --out-file output/main.js ``` ### 监测文件改变 想要在每一次修改文件后编译文件,请使用 `--watch` 或 `-w` 选项 ```bash $ babel src/main.js --watch --out-file output/main.js ``` ## 使用 Source Maps 编译 如果你想添加一个 **source map 文件** 你可以用 `--source-maps` 或者 `-s`。[了解更多关于 source maps](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/) ```bash $ babel src/main.js --out-file output/main.js --source-maps ``` 如果你想使用 内联的 source maps,你可以使用 `--source-maps inline`。 ```bash $ babel src/main.js --out-file output/main.js --source-maps inline ``` ## 编译目录 编译整个 `src` 目录并将其输出到 `lib` 目录。你可以使用 `--out-dir` 或 `-d`。这不会覆盖 `lib` 中的任何其他文件或目录。 ```bash $ babel src --out-dir output ``` 编译整个 src 目录并将其输出到单个文件中。 ```bash $ babel src --out-file main.js ``` 使用 `--ignore` 忽略指定的文件。 ``` babel src --out-dir output --ignore spec.js,test.js ``` 使用 `--copy-files`