npm下載下面幾個(gè)依賴包(npm i -D 以下包名)
gulp
gulp-uglify
gulp-babel
babel-plugin-transform-runtime(這個(gè)可能用不到)
babel-preset-es2015
babel-preset-es2016
babel-preset-es2017
將下列代碼寫入gulpfile.js中
const gulp=require("gulp");
const uglify=require("gulp-uglify");
const babel = require('gulp-babel');
gulp.task('babel',function() {
return gulp.src('./src/js/*.js')//輸入文件(改成自己對(duì)應(yīng)路徑)
.pipe(babel({
presets: ['es2015', 'es2016', 'es2017'],
plugins: [["transform-runtime", { "polyfill": false,"regenerator": true}]]
}))//將es7轉(zhuǎn)換es5
.pipe(uglify())//壓縮js
.pipe(gulp.dest("./dist/js")) //輸出到目錄(改成自己對(duì)應(yīng)路徑)
});
在終端代碼里面運(yùn)行命令
gulp babel