Home > Web Front-end > JS Tutorial > body text

Example analysis of converting es6 to es5 in gulp

黄舟
Release: 2017-07-24 13:43:35
Original
1949 people have browsed it

Instance analysis of converting es6 to es5 in gulp

npm install --save-dev gulp-babel  babel-preset-es2015
Copy after login
var babel = require("gulp-babel");
// es6
gulp.task('es6', function() {
    return gulp.src('./wuqian/**/*.js')
        .pipe(babel())
        .pipe(gulp.dest('dist/'));
});
Copy after login

Create the file .babelrc in the project root path. The content is

{  "presets": ["es2015"]
}
Copy after login

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 存放的路径  
});
Copy after login

ES6 example:

let [foo, [[bar], baz]] = [1, [[2], 3]];  
console.log(foo);  
console.log(bar);  
console.log(baz);
Copy after login

Converted es5:

"use strict";  
  
var foo = 1,  
    bar = 2,  
    baz = 3;  
  
console.log(foo);  
console.log(bar);  
console.log(baz);
Copy after login


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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template