[英]How do I watchify multiple targets in Gulp?
我正在使用 browserify 來監聽將多個文件編譯成多個目標,就像這樣(使用這個技巧):
gulp.task('js', function () {
var bundler = through2.obj(function (file, enc, next) {
browserify(file.path).bundle(function(err, res) {
file.contents = res;
next(null, file);
});
});
return gulp.src(['foo.js', 'bar.js'])
.pipe(bundler)
.pipe(uglify())
// Other pipes
.pipe(gulp.dest('./compiled'));
});
如何將此 through2 用法與 watchify 結合使用? 關於使用乙烯基源流的常見建議對我不起作用。 我想生成兩個文件(compiled/foo.js 和compiled/bar.js)。 我不想將這些文件合二為一。
我想出了如何結合 through2 和 watchify。 訣竅是不要在更新時調用next()
:
var bundler = through.obj(function (file, enc, next) {
var b = watchify(browserify(file.path))
b.on('update', function () {
gutil.log('Updated', gutil.colors.magenta(file.path));
b.bundle(function (err, res) {
file.contents = res;
// Do not call next!
});
b.on('log', gutil.log);
}
b.bundle(function (err, res) {
file.contents = res;
next(null, file);
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.