Gulp with watchify/browserify 运行一次,然后停止观看



我有以下吞咽任务(最初来自此博客):

var path = {
    MAIN_JSX: './myapp/app/jsx/main.js',
    APP_DIR: 'myapp/app',
    APP_JS: 'app.js',
};
gulp.task('watch', function() {
    var watcher = watchify(browserify({
        entries: [path.MAIN_JSX],
        transform: [reactify],
        debug: true,
        cache: {}, packageCache: {}, fullPaths: true
    }));
    return watcher.on('update', function () {
        watcher
            .bundle()
            .on('error', function(err) {
                console.log(err.message)
                this.end();
            })
            .pipe(source(path.APP_JS))
            .pipe(gulp.dest(path.APP_DIR));
        console.log('Updated on ' + (new Date().toString()));
    })
        .bundle()
        .on('error', function(err) {
            console.log(err.message)
            this.end();
        })
        .pipe(source(path.APP_JS))
        .pipe(gulp.dest(path.APP_DIR));
});
gulp.task('default', ['watch']);

该任务在我第一次发出gulp命令时运行;然后第一次更新main.js文件。之后它根本不运行。这是怎么回事?

在Github上有很多关于这个问题的讨论。

虽然听起来可能有很多事情会导致这个问题,但我在 Ubuntu 14.04 上遵循了相同的教程,对我有用的是使用 Watchify 的轮询功能:

var watcher = watchify(..., {poll: true});

从Github上的讨论来看,这听起来对某些人有效,但对其他人无效。

最新更新