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 will ensure that Gulp watch will continue to run.
However, when I try it, I keep on getting this error message, which causes Gulp to stop:
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. 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!