![](/img/trans.png)
[英]Why watch task terminate in gulp already use gulp-plumber plugin?
[英]gulp-plumber throws error then stops build.
gulp-plumber
遇到了问题,因为它因抛出错误而中断了我的构建。
例如,我使用无效的语法(例如padding-left:woah-err
对scss
进行了更改。 水管工在终端通知我错误。 然后我回到scss
文件,将其更改为padding-left:20px;
保存并在终端中没有任何响应 ,看来我的gulp构建已损坏...要修复,我不得不重新启动gulp。
但是在我的this.emit('end');
文件中,如果我更改this.emit('end');
到this.emit();
构建不会中断,但是我再也没有收到关于错误的管道工通知。
我想改变我配置水暖工的方式,以使其正常工作。 有什么建议么? 这看起来是一个很好的解决方案 。
这是我的包裹
var gulp = require('gulp'),
fs = require('fs'),
gulpif = require('gulp-if'), // condtionally run task
plumber = require('gulp-plumber'), // prevent pipe breaking
browserSync = require('browser-sync').create(),
bower = require('gulp-bower'), // gulp bower
concat = require('gulp-concat'), // concat files
cssmin = require('gulp-minify-css'), // minify css
rename = require('gulp-rename'), // rename file
runSequence = require('run-sequence'), // runs gulp tasks in order
sass = require('gulp-sass'), // css preprocessor
uglify = require('gulp-uglify'); // minify js
这是我的样式任务(有人帮助我进行设置)。可能要重新考虑它的结构。 接受建议
// Styles Task
gulp.task('styles', function(){
// streamError is set to false
var streamError = false;
return gulp.src(paths.source.styles)
.pipe(plumber({
// plumber finds errors in stream
errorHandeler:function(error){
streamError = error;
// plumber logs errors to console and terminal
console.log(streamError.message);
browserSync.notify(streamError.message,errorTimeout);
this.emit('end');
}
}))
.pipe(sass())
// compile sass
.pipe(gulp.dest(paths.destination.styles))
// if the streamError is NOT false reload browser
.pipe(gulpif(!streamError,browserSync.reload({stream:true})))
.pipe(cssmin()) // min css
.pipe(rename({ // rename file to site.min.css
suffix:'.min'
}))
.pipe(gulp.dest(paths.destination.styles))
// if streamError is not `false` reload browser
.pipe(gulpif(!streamError,browserSync.reload({stream:true})));
});
这为我解决了问题。
Using gulp-plumber 1.1.0
function onError(err) {
console.log(err); //or other way you may prefer to log
this.emit('end');
}
gulp.task('myTask', function(){
return gulp
.src('myFilePath')
.pipe(plumber(onError))
[...]
}
希望这个帮助
我认为是因为发生错误时,Gulp没有收到完成的回调。
您可能需要在任务函数中添加完成的参数。
如果有错误,您将手动调用done()。 简单:
// Styles Task
gulp.task('styles', function( done /** done! **/){
// streamError is set to false
var streamError = false;
return gulp.src(paths.source.styles)
.pipe(plumber({
// plumber finds errors in stream
errorHandeler:function(error){
streamError = error;
// plumber logs errors to console and terminal
console.log(streamError.message);
browserSync.notify(streamError.message,errorTimeout);
this.emit('end');
done();//call done here!
}
}))
//keep the same.....
});
希望对你有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.