[英]gulp-plumber throws error then stops build.
Having an issue with gulp-plumber
as it breaks my build upon a error throw. gulp-plumber
遇到了问题,因为它因抛出错误而中断了我的构建。
For example I make a change to my scss
with an invalid syntax such as padding-left:woah-err
. 例如,我使用无效的语法(例如
padding-left:woah-err
对scss
进行了更改。 Plumber notifies me in the terminal of the error. 水管工在终端通知我错误。 Then I got back to
scss
file make the change to padding-left:20px;
然后我回到
scss
文件,将其更改为padding-left:20px;
save and get no response in terminal and it looks like my gulp build is broken...To fix I haft to restart gulp. 保存并在终端中没有任何响应 ,看来我的gulp构建已损坏...要修复,我不得不重新启动gulp。
However inside my gulp file if I change this.emit('end');
但是在我的
this.emit('end');
文件中,如果我更改this.emit('end');
to this.emit();
到
this.emit();
the build dose not break but I get no plumber notifications of errors anymore. 构建不会中断,但是我再也没有收到关于错误的管道工通知。
Looking into changing up the way my I configured my plumber to get this to work right. 我想改变我配置水暖工的方式,以使其正常工作。 Any suggestions?
有什么建议么? This looks like a good solution .
这看起来是一个很好的解决方案 。
Here's my packages 这是我的包裹
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
Here's my styles task (had someone help me set this up)..Might want to rethink it's structure. 这是我的样式任务(有人帮助我进行设置)。可能要重新考虑它的结构。 Open to suggestions
接受建议
// 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})));
});
This fixed the problem for me. 这为我解决了问题。
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))
[...]
}
Hope this help 希望这个帮助
I think because when error happens, Gulp didnt receive the finished callback; 我认为是因为发生错误时,Gulp没有收到完成的回调。
You may need add a done param to your task function. 您可能需要在任务函数中添加完成的参数。
if there is error, you will call done() manually. 如果有错误,您将手动调用done()。 Simple:
简单:
// 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.....
});
hope it's help 希望对你有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.