问题
Is it possible to create a global OnError function that I can pass a title and the error message to?
I'm looking to do something like this for all tasks ran with plumber:
onError = function(error) {
$.notify.onError({
title: 'Error',
subtitle: '<%= file.relative %> did not compile!',
message: '<%= error.message %>'
})(error);
};
回答1:
You can simply save the onError function as a variable:
var onError = notify.onError({
title: 'Error',
subtitle: '<%= file.relative %> did not compile!',
message: '<%= error.message %>'
});
And in several different gulp-tasks and plumber-functions:
gulp.src('./src/*.ext')
.pipe(plumber({ errorHandler: onError }))
.pipe(coffee())
.pipe(gulp.dest('./dist'));
and somewhere else:
gulp.src('./src/*.scss')
.pipe(plumber({ errorHandler: onError }))
.pipe(sass())
.pipe(uglify())
.pipe(plumber.stop())
.pipe(gulp.dest('./dist'));
来源:https://stackoverflow.com/questions/25782341/global-error-message-using-gulp-notify-plumber