I am leveraging browserify to utilize npm modules in my front end code, and I use gulp for my build tasks. The setup is functioning smoothly:
const browserify = require('gulp-browserify');
gulp.task('js', ['clean'], function() {
gulp
.src('./public/js/src/index.js')
.pipe(browserify({
insertGlobals : true,
debug : ! gulp.env.production
}))
.pipe(gulp.dest('./public/js/dist'))
});
Nevertheless, if there happens to be a syntax error in my JS, I would like to receive an OS X notification indicating the error. I came across a similar query and made adjustments to my code by including an .on('error'...)
right after the .browserify()
:
// Browserify/bundle the JS.
gulp
.src('./public/js/src/index.js')
.pipe(browserify({
insertGlobals : true,
debug : ! gulp.env.production
}).on('error', function(err){
notify.onError({
message: "Error: <%= error.message %>",
title: "Failed running browserify"
}
this.emit('end');
})
.pipe(gulp.dest('./public/js/dist'))
However, this method does not send notifications when my JS code is broken. Even adding a console.log() inside on('error',...)
doesn't log anything. My suspicion is that this issue arises because the question mentioned does not involve using gulp piping.
How can I receive alerts about errors while piping to gulp browserify?