我與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