The return from this function needs to be a stream. In non-watch mode that's easy; just return rebundle, browserify stream is converted, blah blah, ok. In watch mode, however, rebundle is run on each update and creates a new stream every time. I need a way to consolidate all of those streams as they're created into a single endless stream that I can return and that can actually be consumed down the line. Playing with combined-stream, it seems like once data is read the stream ceases to be writable, so that's a no go. Any help would be appreciated!
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 ????
}