[英]Stop gulp pipeline from executing when jshint fails
I am using gulp to run a developer web server and I want the following tasks to happen when a change occurs to a javascript file: 我正在使用gulp来运行开发人员Web服务器,并且我希望在javascript文件发生更改时发生以下任务:
I've seen in other examples to use jshint.reporter('fail') as shown in the code below, to stop the rest of the pipeline. 我在其他示例中看到使用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());
However when I do this it appears to always stop regardless of whether or not the lint was a success. 然而,当我这样做时,无论棉绒是否成功,它似乎总是停止。 So, how can I end the pipeline after a failed linting?
那么,如何在掉毛失败后结束管道?
Not sure if this is the best solution, but it works: 不确定这是否是最佳解决方案,但它有效:
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);
what you can do is plugin plumber
to exit in case of error 您可以做的是插件
plumber
在出错时退出
so pipe the plumber in the linting process 因此在管道工程中管道工
.pipe(plumber(_doExit))
here is how you defined _doExit 这是你如何定义_doExit
function _doExit() {
process.exit(1);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.