2014-02-25 42 views
5

我使用亚组的Watchify更好Browserify建立,一饮而尽手表任务中,像这样:整合一饮而尽,livereload与Watchify

var gulp = require('gulp'); 
var source = require('vinyl-source-stream'); 
var watchify = require('watchify'); 

var hbsfy = require("hbsfy").configure({ 
    extensions: ["html"] 
}); 

gulp.task('watch', function() { 
    var bundler = watchify('./public/js/app.js'); 

    bundler.transform(hbsfy); 

    bundler.on('update', rebundle); 

    function rebundle() { 
     return bundler.bundle() 
      .pipe(source('bundle.js')) 
      .pipe(gulp.dest('./public/dist/js/')); 
    } 

    return rebundle(); 
}); 

试图找出我如何可以将现场重新放回任务,所以它在Watchify完成它的事情时触发。任何想法我会如何做到这一点?

回答

7

您是否试过在gulp.dest()之后使用gulp-livereload

你应该能够简单地插入这样的:

.pipe(livereload()) 

这假定bundler.bundle()管道正确的数据类型。

+1

[vinyl-source-stream](https://github.com/hughsk/vinyl-source-stream)('.pipe(source('bundle.js'))'在他的代码中)将文本流从'bundler.bundle()'管道输出,并使其成为gulp使用的乙烯文件流,替换'gulp.src()'。因此,其他的一些插件可以在那之后传输。 – DSKrepps

+0

啊,谢谢,我没有看到那一行。很高兴知道! – OverZealous

+1

另请注意,如果你使用gulp-connect,你可以'.pipe(connect.reload())' –