当gulp-eslint失败时抛出gulp-notify消息

我试图在我的ESlint任务检测到错误时使用gulp-notify,但是我不能使它工作,因为gulp-notify需要在一些Node.jsstream之后用pipe道引用。

我可以用下面的代码“部分工作”

return gulp.src([config.js.all, '!app/assets/scripts/vendor/**']) .pipe(eslint()) .pipe(plumber()) .pipe(eslint.format()) .pipe(notify('Error!!!')) .pipe(eslint.failAfterError()); 

然而,总是抛出消息,不仅当我有错误。

我可以使用下面的语法在gulp-eslint中得到错误:

 return gulp.src([config.js.all, '!app/assets/scripts/vendor/**']) .pipe(eslint()) .pipe(plumber()) .pipe(eslint.format()) .pipe(notify('Error!!!')) .pipe(eslint.result(function (result) { if(result.errorCount > 0){ console.log('Error'); } })) .pipe(eslint.failAfterError()); 

当有错误时,我会返回console.log,我需要的是让gulp-notify在上面的代码中发送一个通知。 有人可以帮我吗?

马修的回答几乎是正确的。 以下是解决方法:

 return gulp.src([config.js.all, '!app/assets/scripts/vendor/**']) .pipe(eslint()) .pipe(plumber()) .pipe(eslint.format()) .pipe(eslint.failAfterError()) .on("error", notify.onError('Error!!!')); // <-- notify after eslint.failAfterError 

很简单。 快乐的林林!

gulp-notify文档给出了几个例子。 在你的情况下,它应该是这样的:

 return gulp.src([config.js.all, '!app/assets/scripts/vendor/**']) .pipe(eslint()) .pipe(plumber()) .pipe(eslint.format()) .on("error",notify.onError('Error!!!')) .pipe(eslint.failAfterError());