天天看點

gulp建構es6轉es5配置

gulp遵循commonjs規範,必須使用module.exports規範導出,require使用

var gulp = require('gulp');

var babel = require('gulp-babel');

var browserify = require('gulp-browserify');

a.js

function fnAlert(msg){

    console.log(msg);

    alert(msg);

}

module.exports={fnAlert}

b.js

var example =require("./a.js");

example.fnAlert(333)

gulp.task('default', () =>

   gulp.src('b.js')

       .pipe(browserify({

           insertGlobals : false,

           debug : false

       }))

        .pipe(babel({

            presets: ['@babel/preset-env']

        }))

        .pipe(gulp.dest('dist'))

);