問題描述
所以,我們整天都在研究新的 FE 工作流程,主要想法是通過觀察者運行一些任務,我們將擁有我們的 IDE 和一個窗口,每次發(fā)生變化時都會刷新瀏覽器(scss、js, html 等).
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).
因此,如果一切順利,我們將什么也看不到:瀏覽器將重新加載,我們將繼續(xù)工作.
So, we wont see nothing if all went good: the browser will get reload and we will keep working.
但是,我們想使用 gulp notify 來處理錯誤,所以萬一我們有問題,會彈出通知程序,此時您可以檢查控制臺并查看錯誤.
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.
失敗時的 sass 任務示例:
Example for our sass task when fail:
對于我們的樣式任務,一切正常,但我無法為 JS 文件完成此操作.
For our styles tasks, everything works fine, but Im not able to accomplish this for JS files.
主要是,我不能讓 gulp-jshint 像我想要的那樣工作.
Mainly, I cant make gulp-jshint works as I want.
這將是這樣的:你保存你的 js 文件,如果失敗,彈出窗口,當你看到這個時,你進入控制臺,你會看到 jshint-stylish 的輸出.
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.
有人可以幫我嗎?
這是我的(非工作)解決方案:
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 ?
請注意,我只想一直發(fā)出相同的消息JS提示失敗"
Note that I just want to emit the same message all the time "JS hint fail"
然后,控制臺(感謝 jshint-stylish)將為我們提供更多信息.
Then, the console (thanks to jshint-stylish) will gave us more info.
此外,這將在一個觀察者身上.JS提示通過后,會執(zhí)行更多的任務,比如borwserify,所以重要的是如果它停止了,等待"直到我完成修復然后繼續(xù).
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.
謝謝!
PS,我正在使用:
吞咽 3.8.10吞咽-jshint 1.8.6吞咽通知 2.0.1
gulp 3.8.10 gulp-jshint 1.8.6 gulp-notify 2.0.1
通過 OSX 10.9.4
Over a OSX 10.9.4
推薦答案
gulp 中的 error
事件僅在流中發(fā)生錯誤時觸發(fā).
The error
event in gulp only fires when an error in the stream occurs.
要將錯誤報告器添加到 gulp-jshint
將其傳遞給 fail
報告器:
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'}));
});
這篇關于當 gulp-jshint 失敗時,無法使 gulp-notify 彈出錯誤消息的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!