【问题标题】:How to handle react errors when using browserify and reactify?使用browserify和reactify时如何处理react错误?
【发布时间】:2015-02-13 22:25:49
【问题描述】:

在我的 Web 应用程序中,我创建了 gulpfile,它通过使用 reactify 和 browserify 来编译反应文件。这是我的捆绑任务的外观:

var bundler = watchify(browserify({
    entries: config.paths.src.js.app,
    transform: [reactify, envify],
    debug: isDevelopment,
    cache: {}, packageCache: {}, fullPaths: true
}), watchify.args);

var bundle = function() {
    start();
    return bundler
        .bundle()
        .on('error', errorLog)
        .pipe(source(config.paths.build.appName))
        .pipe(gulpif(!isDevelopment, streamify(uglify())))
        .pipe(gulp.dest(config.paths.build.folder))
        .pipe(reload({stream:true}))
        .on('end', end);

};

function errorLog(error) {
    log('******  Start of Error  ******');
    gutil.log(gutil.colors.red(error.message));
    log('******  End of Error  ******');
}

问题是当错误发生时,我的 gulp 崩溃了。不知道怎么处理。在这种情况下,水管工不起作用。有什么想法吗?

【问题讨论】:

    标签: javascript gulp reactjs browserify


    【解决方案1】:

    This helped me

    尝试将this.emit('end'); 添加到errorLog

    function errorLog(error) {
        log('******  Start of Error  ******');
        gutil.log(gutil.colors.red(error.message));
        log('******  End of Error  ******');
        this.emit('end');
    }
    

    【讨论】:

    • this.emit('end') 结束我不想要的任务。我想显示错误并且仍在后台运行 browserify/watchify 任务。使用此代码,我将不得不在每个错误后手动重新运行任务。
    猜你喜欢
    • 1970-01-01
    • 2015-04-20
    • 1970-01-01
    • 2015-08-05
    • 2018-08-26
    • 1970-01-01
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    相关资源
    最近更新 更多