此函数的返回需要是一个流。在非手表模式下,这很容易;只需返回重新捆绑,browserify 流被转换,等等等等,好的。但是,在监视模式下,每次更新都会运行重新捆绑,并且每次都会创建一个新流。我需要一种方法来整合所有这些流,因为它们被创建成一个我可以返回的无限流,并且实际上可以在生产线上消耗掉。使用组合流,似乎一旦读取数据,流就不再是可写的,所以这是不行的。任何帮助,将不胜感激!
var bundleify = function(watch) {
var bundler = (watch?watchify:browserify)('main.js');
var rebundle = function () {
return bundler.bundle()
.on('error', console.log)
.pipe(source('main.js'))
.pipe(rename('app.js'))
.pipe(jsTasks()); // lazypipe with other tasks
};
// Regular browserify, just return the stream.
if (!watch) {
return rebundle();
}
// Watchify, rebundle on update.
bundler.on('update', function() {
rebundle();
});
// return ????
}