转es5语法
$_> npm i -D gulp-babel@7.0.1 babel-preset-es2015 babel-core
'use strict';
let gulp = require('gulp');
let del = require('del');
let babel = require('gulp-babel');
gulp.task("default", function () {
return gulp.src("./js/*.js")
.pipe(babel())
.pipe(gulp.dest("dist"));
});
提供es6方法
$_> npm i -D babel-polyfill
// index.js
require('babel-polyfill');
打包js
$_> npm i -D browserify vinyl-source-stream vinyl-buffer gulp-sourcemaps babelify@8 gulp-babel@7.0.1 babel-preset-es2015 babel-core
'use strict';
var gulp = require("gulp");
var browserify = require("browserify");
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
let babelify = require('babelify');
gulp.task("default", function () {
return browserify({
entries: "./src/js/index.js",
})
.transform(['babelify'])
.bundle()
.pipe(source("index.js"))
.pipe(buffer())
.pipe(gulp.dest("./dist"));
});
// .babelrc
{
"presets": ["es2015"]
}