我与Gulp有很多相同的问题,因为管道到多个目的地的各种任务似乎很难或可能不可能。另外,为一个任务设置多个流似乎效率低下,但我想这是现在的解决方案。
对于我目前的项目,我需要多个捆绑与各种页面相关联。修改咕嘟咕嘟入门
https://github.com/greypants/gulp-starter
browserify/watchify任务:
https://github.com/dtothefp/gulp-assemble-browserify/blob/master/gulp/tasks/browserify.js
我用glob模块回调的内部foreach循环:
gulp.task('browserify', function() {
var bundleMethod = global.isWatching ? watchify : browserify;
var bundle = function(filePath, index) {
var splitPath = filePath.split('/');
var bundler = bundleMethod({
// Specify the entry point of your app
entries: [filePath],
// Add file extentions to make optional in your requires
extensions: ['.coffee', '.hbs', '.html'],
// Enable source maps!
debug: true
});
if(index === 0) {
// Log when bundling starts
bundleLogger.start();
}
bundler
.transform(partialify)
//.transform(stringify(['.html']))
.bundle()
// Report compile errors
.on('error', handleErrors)
// Use vinyl-source-stream to make the
// stream gulp compatible. Specifiy the
// desired output filename here.
.pipe(source(splitPath[splitPath.length - 1]))
// Specify the output destination
.pipe(gulp.dest('./build/js/pages'));
if(index === (files.length - 1)) {
// Log when bundling completes!
bundler.on('end', bundleLogger.end);
}
if(global.isWatching) {
// Rebundle with watchify on changes.
bundler.on('update', function(changedFiles) {
// Passes an array of changed file paths
changedFiles.forEach(function(filePath, index) {
bundle(filePath, index);
});
});
}
}
// Use globbing to create multiple bundles
var files = glob('src/js/pages/*.js', function(err, files) {
files.forEach(function(file, index) {
bundle(process.cwd() + '/' + file, index);
})
});
});
我们不能保存束(), 'VAR束= browserify(” ./ SRC/index.js')的输出束();' ,然后将其馈送到2不同的'管道'? 像 'bundle.pipe(源( 'bundle.js'))管(gulp.dest(” ./ DIST '));'和'bundle.pipe(重命名(' bundle.min.js') ).pipe(streamify(丑化()) .pipe(gulp.dest( './ DIST'));' 所以束被运行一次,我们使用输出两次 – AntouanK
从中吞的版本这个错误是固定的。 ? –
@AlirezaMirian +1因为想知道它被修复了哪个版本 – anjunatl