babel

Babel

2016-03-16  本文已影响209人  iOS_成才录

1、Babel简介

https://babeljs.io/
https://www.npmjs.com/package/babel-core

2、Bable安装

suto  npm install -g babel // 完成后,我们就可以使用babel命令行工具了, 如何没有权限,要加上 suto

3、Babel命令基础

 'use strict';

 let breakfast = (dessert, drink) => dessert + drink;
 cd 进入项目所在目录
 babel script.js // 会直接在这里显示编译好的代码在终端中
  babel 常用命令:

Compile Files

Compile the file script.js and output to stdout.

$ babel script.js
# output...
If you would like to output to a file you may use --out-file or -o.

$ babel script.js --out-file script-compiled.js
To compile a file every time that you change it, use the --watch or -w option:

$ babel script.js --watch --out-file script-compiled.js
Compile with Source Maps
If you would then like to add a source map file you can use --source-maps or -s. Learn more about source maps.

$ babel script.js --out-file script-compiled.js --source-maps
If you would rather have inline source maps, you may use --source-maps inline.

$ babel script.js --out-file script-compiled.js --source-maps inline
Compile Directories
Compile the entire src directory and output it to the lib directory. You may use --out-dir or -d.

$ babel src --out-dir lib
Compile the entire src directory and output it to the one concatenated file.

$ babel src --out-file script-compiled.js
Piping Files
Pipe a file in via stdin and output it to script-compiled.js

$ babel --out-file script-compiled.js < script.js

上一篇 下一篇

猜你喜欢

热点阅读