![](/img/trans.png)
[英]Cant make gulp-notify to pop up a error message when gulp-jshint fail
[英]Throw a gulp-notify message when gulp-eslint fails
当我的 ESlint 任务检测到错误时,我尝试使用 gulp-notify,但我无法使其工作,因为需要在某些 Node.js 流之后使用管道引用 gulp-notify。
我可以使用以下代码部分“使其工作”:
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());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.