您的
swallowError函数应如下所示:
function swallowError (error) { // If you want details of the error in the console console.log(error.toString()) this.emit('end')}我认为您必须
error在任务下降而不是
watch任务下降时绑定此函数,因为这不是问题所在,因此应在每个可能失败的任务上设置此错误回调,例如当您遇到故障时插件会中断错过了一个
;或其他东西,以防止
watch任务停止。
例子 :
gulp.task('all', function () { gulp.src('./app/script/*.coffee') .pipe(coffee({ bare: true })) .on('error', swallowError) .pipe(gulp.dest('./public/js')) gulp.src('css/*.scss') .pipe(sass({ compass: true })) .on('error', swallowError) .pipe(cssmin()) .pipe(gulp.dest('dist'))})或者,如果您不介意包含另一个模块,则可以使用 gulp-util 的
log 函数,以防止您在自己的函数中声明其他函数:
gulpfile
.on('error', gutil.log)但我建议您看一下很棒的 gulp-plumber
插件,该插件用于删除事件的
onerror处理程序
error,从而导致流中断。它非常简单易用,可阻止您捕获所有可能失败的任务。
gulp.src('./app/script/*.coffee') .pipe(plumber()) .pipe(coffee({ bare: true })) .pipe(gulp.dest('./public/js'))有关插件的创建者在本文上提供了有关此内容的更多信息。



