1. Create a Gulp project

Gulpfile. js,.babelrc, app /es6.js, dist

2. The initialization

$ npm init

3. Install the plug-in

Install gulp

$ cnpm install gulp –save-dev

Install gulp-babel, babel-core and babel-preset- ES2015

$CNPM install [email protected] babel-core babel-preset-es2015 –save-dev

Note: gulp-babel cannot be later than 8.0.0, otherwise an error will occur

4. Contents of project files

.babelrc file

{
  "presets": ["es2015"]}Copy the code

To gulpfile.js

const gulp = require('gulp'),  
  babel = require('gulp-babel');  

gulp.task('es6', () = > {return gulp.src('app/*.js')
    .pipe(babel())
    .pipe(gulp.dest('dist'));
});

Copy the code

In the es6.js file

let name = "hello world";  
console.log(name);  
Copy the code

5. Transformation of ES5

Enter commands on the command line

gulp es6

Find the converted es5 file content under DIST

"use strict";

var name = "liuliu";
console.log(name);
Copy the code

Add a.babelrc file to the root directory using the directory structure used to create projects using gulp