- npm install --save-dev gulp
- npm install --save-dev gulp-babel
- npm install --save-dev babel-preset-es2015
gulp配置如下:
- var gulp = require("gulp");
- var babel = require("gulp-babel");
- gulp.task("default", function () {
- return gulp.src("js**/*.js")// ES6 源码存放的路径
- .pipe(babel({
- presets: ['es2015']
- }))
- .pipe(gulp.dest("dist")); //转换成 ES5 存放的路径
- });
ES6列子:
- let [foo, [[bar], baz]] = [1, [[2], 3]];
- console.log(foo);
- console.log(bar);
- console.log(baz);
转换后的es5:
- "use strict";
- var foo = 1,
- bar = 2,
- baz = 3;
- console.log(foo);
- console.log(bar);
- console.log(baz);