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

时间:2015-04-27 02:09:11

标签: reactjs gulp browserify watchify

我有以下gulp任务(最初来自this blog):

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文件。之后它根本就没有运行。这里有什么问题?

1 个答案:

答案 0 :(得分:0)

有很多关于这个问题的讨论here on Github

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

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

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

相关问题