![](/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.