嗨,我正在寻找一个公共包,其中包含多个页面共享的依赖项和每个页面的页面特定包。
我可以使用它来创建多个捆绑包:browserify-multiple-destination
但我需要创建具有共享依赖项的公共文件以避免重复。
是否可以在此任务中包含因子捆绑以分离常见的依赖项?
B rowserify + Globs(多目的地)配方
var gulp = require('gulp');
var browserify = require('browserify');
var gutil = require('gulp-util');
var tap = require('gulp-tap');
var buffer = require('gulp-buffer');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
gulp.task('js', function () {
return gulp.src('src/**/*.js', {read: false}) // no need of reading file because browserify does.
// transform file objects using gulp-tap plugin
.pipe(tap(function (file) {
gutil.log('bundling ' + file.path);
// replace file contents with browserify's bundle stream
file.contents = browserify(file.path, {debug: true}).bundle();
}))
// transform streaming contents into buffer contents (because gulp-sourcemaps does not support streaming contents)
.pipe(buffer())
// load and init sourcemaps
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(uglify())
// write sourcemaps
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('dest'));
});