const gulp = require(‘gulp’), less = require(‘gulp-less’), autoprefixer = require(‘gulp-autoprefixer’), minifyCSS = require(‘gulp-minify-css’), map = require(“map-stream”), uglify = require(‘gulp-uglify’), gutil = require(‘gulp-util’), clean = require(‘gulp-clean’), concat = require(‘gulp-concat’), combiner = require(‘stream-combiner2’), browserify = require(‘browserify’), babelify = require(‘babelify’), source = require(‘vinyl-source-stream’), buffer = require(‘vinyl-buffer’), sourcemaps = require(‘gulp-sourcemaps’), vueify = require(‘vueify’), envify = require(‘envify/custom’), runSequence = require(‘run-sequence’), gulpSequence = require(‘gulp-sequence’)
vueify.compiler.applyConfig(require(’./configs/vue.config.js’));
var b = browserify(’./src/main.js’,require(’./configs/browserify.config.js’))
.transform(babelify) //使用ES6转换到ES5的语法编译
.transform(‘browserify-css’, {global: true}) //link injected css
.transform(vueify) //编译vue模板
.transform(
// 必填项,以处理 node_modules 里的文件
{ global: true },
envify({ NODE_ENV: ‘development’ })
)
combiner.obj([
b.bundle(), //开始连接并捆绑所有文件
source(‘bundle.js’), //命名捆绑成的文件,并当作源文件
buffer(),
sourcemaps.init({loadMaps: true}), //生成map
uglify().on(‘error’, gutil.log), //压缩
sourcemaps.write(’./’), //map文件相对压缩文件的位置
gulp.dest(’./build/public/js’) // 压缩文件的相对输出位置
])
.on(‘error’, console.error.bind(console)); //确认开启报错