![](/img/trans.png)
[英]“Use the function form of ”use strict" when using Gulp + Babel + JsHint
[英]Stop gulp pipeline from executing when jshint fails
我正在使用gulp來運行開發人員Web服務器,並且我希望在javascript文件發生更改時發生以下任務:
我在其他示例中看到使用jshint.reporter('fail'),如下面的代碼所示,以停止管道的其余部分。
var jshint = require('gulp-jshint'),
watch = require('gulp-watch');
watch('resources/js/src/**/*.js', function() {
util.log('Changes to js source files detected');
}).pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'))
.pipe(gulp.dest('.tmp/js/src/'))
.pipe(connect.reload());
然而,當我這樣做時,無論棉絨是否成功,它似乎總是停止。 那么,如何在掉毛失敗后結束管道?
不確定這是否是最佳解決方案,但它有效:
var map = require('map-stream');
...
var copyAndReload = map(function (file, cb) {
if (file.jshint.success) {
gulp.src('resources/js/src/**/*.js')
.pipe(gulp.dest('.tmp/js/src/'))
.pipe(connect.reload());
}
});
watch('resources/js/src/**/*.js', function() {
util.log('Changes to js source files detected');
}).pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(copyAndReload);
您可以做的是插件plumber
在出錯時退出
因此在管道工程中管道工
.pipe(plumber(_doExit))
這是你如何定義_doExit
function _doExit() {
process.exit(1);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.