问题
So, was the whole day working on our new FE workflow, the main idea is to run a few tasks through a watcher, we will have our IDE's and a window with the browsers getting refreshed each time something change (scss, js, html, etc).
So, we wont see nothing if all went good: the browser will get reload and we will keep working.
But, we want to use gulp notify for errors, so in case we have something wrong, the notifier pop up will appear, and at that point, you can check the console and see the error.
Example for our sass task when fail:
For our styles tasks, everything works fine, but Im not able to accomplish this for JS files.
Mainly, I cant make gulp-jshint works as I want.
Which will be like this: you save your js file, if it fails, the popup appear and when you see this, you go to the console and you see the output of jshint-stylish.
Can somebody help me ?
This is my (non working) solution:
gulp.task( 'js-hint', function() {
return gulp.src( config.source )
.pipe( plumber() )
.pipe( jshint( config.jsHintRules ) )
.pipe( jshint.reporter( 'jshint-stylish' ) )
.on('error', notify.onError( { message: 'JS hint fail' } ) );
});
Obviously, I have a problem with concepts, so, will somebody can please put me on the right direction ?
Note that I just want to emit the same message all the time "JS hint fail"
Then, the console (thanks to jshint-stylish) will gave us more info.
Also, this will be on a watcher. After JS hint pass, will execute more tasks, like borwserify, so its important that if its stop, "wait" till I finish fixing it and then keep going.
Thanks !
PS, Im using:
gulp 3.8.10 gulp-jshint 1.8.6 gulp-notify 2.0.1
Over a OSX 10.9.4
回答1:
The error
event in gulp only fires when an error in the stream occurs.
To add an error reporter to gulp-jshint
pass it through the fail
reporter:
gulp.task('js-hint', function() {
return gulp.src(config.source)
.pipe(plumber())
.pipe(jshint( config.jsHintRules))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'))
.on('error', notify.onError({ message: 'JS hint fail'}));
});
来源:https://stackoverflow.com/questions/28115226/cant-make-gulp-notify-to-pop-up-a-error-message-when-gulp-jshint-fail