[英]Gulp: Error Messages and Notifications with Plumber
In this example , it states you can use Gulp-Plumber and Gulp-Notify to display a message and sound each time there is an error. 在此示例中 ,它指出您可以在每次出现错误时使用Gulp-Plumber和Gulp-Notify来显示消息和声音。 Gulp-Plumber will ensure that Gulp watch will continue to run.
Gulp-Plumber将确保Gulp手表将继续运行。
However, when I try it, I keep on getting this error message, which causes Gulp to stop: 但是,当我尝试它时,我不断收到此错误消息,这导致Gulp停止:
events.js:72
throw er; // Unhandled 'error' event
Here is my code: 这是我的代码:
var gulp = require('gulp'),
sass = require('gulp-ruby-sass'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
notify = require('gulp-notify'),
plumber = require('gulp-plumber'),
var onError = function(err) {
notify.onError({
title: "Gulp",
subtitle: "Failure!",
message: "Error: <%= error.message %>",
sound: "Beep"
})(err);
this.emit('end');
};
//Scripts Task
gulp.task('scripts', function() {
gulp.src('frontend/build/js/*.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(concat('main.js'))
.pipe(gulp.dest('frontend/dist/js'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest('frontend/dist/scripts'))
.pipe(notify({
sound: "Frog"
}));
});
//Styles Task
gulp.task('styles', function() {
return sass('frontend/build/scss/', {style: 'expanded'})
.pipe(plumber({errorHandler: onError}))
.pipe(gulp.dest('frontend/dist/css/'))
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist/styles'))
.pipe(notify({ // Add gulpif here
sound: "Pop"
}));
});
The only difference between my code and the example is that I have moved onError as a global function so it can be used in both the scripts and styles task. 我的代码和示例之间的唯一区别是,我已将onError作为全局函数移动,因此可以在脚本和样式任务中使用它。 However, even if I move it back inside the styles function, the same error message occurs.
但是,即使我将其移回样式函数内部,也会出现相同的错误消息。
(the code I have posted is abbreviated, the full code can be found here ) (我发布的代码是缩写,完整的代码可以在这里找到)
Also, is there a way to hide the notification message on success so I just get the sound? 另外,有没有一种方法可以在成功时隐藏通知消息,这样我就可以听到声音了? Thanks!
谢谢!
您可能现在已经知道了这一点,但是在完整的代码中,onError函数的作用范围是您的样式任务,您也没有在脚本任务的任何地方使用管道工。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.