【问题标题】:Gulp with watchify/browserify runs once then stops watching带有 watchify/browserify 的 Gulp 运行一次然后停止观看
【发布时间】:2015-07-05 08:02:45
【问题描述】:

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

【问题讨论】:

  • 我看不出它本身有什么问题(尽管从.bundle()gulp.dest() 复制代码是个坏主意)。 browserify 和 watchify 有哪些版本?如果您消除 gulp 部分,那么在 main.js 的后续更新中重新打包是否有任何不同?

标签: reactjs gulp browserify watchify


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2015-01-31
    • 2016-09-14
    • 2016-02-22
    • 2016-07-05
    • 1970-01-01
    • 2014-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多