Instance analysis of converting es6 to es5 in gulp
npm install --save-dev gulp-babel babel-preset-es2015
var babel = require("gulp-babel"); // es6 gulp.task('es6', function() { return gulp.src('./wuqian/**/*.js') .pipe(babel()) .pipe(gulp.dest('dist/')); });
Create the file .babelrc in the project root path. The content is
{ "presets": ["es2015"] }
gulp configuration is as follows:
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 example:
let [foo, [[bar], baz]] = [1, [[2], 3]]; console.log(foo); console.log(bar); console.log(baz);
Converted es5:
"use strict"; var foo = 1, bar = 2, baz = 3; console.log(foo); console.log(bar); console.log(baz);
The above is the detailed content of Example analysis of converting es6 to es5 in gulp. For more information, please follow other related articles on the PHP Chinese website!