标签:
需要 var es = require(‘event-stream‘);
gulp.task(‘browserify‘, function(){ var files = [ { fpath: ‘./js/main.js‘, fname: ‘main.js‘ }, { fpath: ‘./js/main2.js‘, fname: ‘main2.js‘ } ]; var tasks = files.map(function(entry){ return browserify({ entries: [entry.fpath] }) .bundle() .pipe(source(entry.fname)) .pipe(buffer()) .pipe(uglify()) .pipe(rename({ extname: ‘.bundle.js‘ })) .pipe(gulp.dest(‘./dist/s/js‘)); }); return es.merge.apply(null, tasks); });
附上完整 gulpfile.js 如下:
‘use strict‘; var gulp = require("gulp"), browserify = require(‘browserify‘), source = require("vinyl-source-stream"), buffer = require(‘vinyl-buffer‘), less = require("gulp-less"), minifyCss = require(‘gulp-minify-css‘), uglify = require(‘gulp-uglify‘), rename = require(‘gulp-rename‘), es = require(‘event-stream‘), watchify = require(‘watchify‘); gulp.task(‘less‘, function(){ gulp.src(‘./less/*.less‘) .pipe(less()) .pipe(minifyCss({ advanced: false, compatibility: ‘ie7‘ })) .pipe(gulp.dest(‘./dist/s/css‘)); }); gulp.task(‘browserify‘, function(){ var files = [ { fpath: ‘./js/main.js‘, fname: ‘main.js‘ }, { fpath: ‘./js/main2.js‘, fname: ‘main2.js‘ } ]; var tasks = files.map(function(entry){ return browserify({ entries: [entry.fpath] }) .bundle() .pipe(source(entry.fname)) .pipe(buffer()) .pipe(uglify()) .pipe(rename({ extname: ‘.bundle.js‘ })) .pipe(gulp.dest(‘./dist/s/js‘)); }); return es.merge.apply(null, tasks); }); gulp.task(‘watch‘, function(){ gulp.watch(‘./less/*.less‘, [‘less‘]); gulp.watch(‘./js/**/*.js‘, [‘browserify‘]); }); gulp.task(‘default‘, [‘less‘, ‘browserify‘]); gulp.task(‘serve‘, [‘less‘, ‘browserify‘, ‘watch‘]);
标签:
原文地址:http://www.cnblogs.com/simpapaya/p/5046146.html