Add basic error handling for `gulp-plumber`

Add `errorHandler` function for basic error handling with plumber, we can now simply fix erroneous SASS and on save it will be recompiled – instead of having to restart the `watch-bs` task.
This commit is contained in:
Larry Williamson 2017-04-21 12:55:44 -04:00 committed by GitHub
parent 60ed4079fd
commit 71b7babfe0
1 changed files with 30 additions and 5 deletions

View File

@ -49,7 +49,12 @@ var cleanCSS = require('gulp-clean-css');
// Prepare the min.css for production (with 2 pipes to be sure that "theme.css" == "theme.min.css") // Prepare the min.css for production (with 2 pipes to be sure that "theme.css" == "theme.min.css")
gulp.task('scss-for-prod', function() { gulp.task('scss-for-prod', function() {
var source = gulp.src('./sass/*.scss') var source = gulp.src('./sass/*.scss')
.pipe(plumber()) .pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sourcemaps.init({loadMaps: true})) .pipe(sourcemaps.init({loadMaps: true}))
.pipe(sass()); .pipe(sass());
@ -73,7 +78,12 @@ gulp.task('scss-for-prod', function() {
// Prepare the child-theme.css for the development environment // Prepare the child-theme.css for the development environment
gulp.task('scss-for-dev', function() { gulp.task('scss-for-dev', function() {
gulp.src('./sass/*.scss') gulp.src('./sass/*.scss')
.pipe(plumber()) .pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sourcemaps.init({loadMaps: true})) .pipe(sourcemaps.init({loadMaps: true}))
.pipe(sass()) .pipe(sass())
.pipe(sourcemaps.write(undefined, { sourceRoot: null })) .pipe(sourcemaps.write(undefined, { sourceRoot: null }))
@ -90,7 +100,12 @@ gulp.task('watch-scss', ['browser-sync'], function () {
// Compiles SCSS files in CSS // Compiles SCSS files in CSS
gulp.task('sass', function () { gulp.task('sass', function () {
var stream = gulp.src('./sass/*.scss') var stream = gulp.src('./sass/*.scss')
.pipe(plumber()) .pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(sass()) .pipe(sass())
.pipe(gulp.dest('./css')) .pipe(gulp.dest('./css'))
.pipe(rename('custom-editor-style.css')) .pipe(rename('custom-editor-style.css'))
@ -126,7 +141,12 @@ gulp.task('imagemin', function(){
gulp.task('cssnano', function(){ gulp.task('cssnano', function(){
return gulp.src('./css/theme.css') return gulp.src('./css/theme.css')
.pipe(sourcemaps.init({loadMaps: true})) .pipe(sourcemaps.init({loadMaps: true}))
.pipe(plumber()) .pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(rename({suffix: '.min'})) .pipe(rename({suffix: '.min'}))
.pipe(cssnano({discardComments: {removeAll: true}})) .pipe(cssnano({discardComments: {removeAll: true}}))
.pipe(sourcemaps.write('./')) .pipe(sourcemaps.write('./'))
@ -136,7 +156,12 @@ gulp.task('cssnano', function(){
gulp.task('minify-css', function() { gulp.task('minify-css', function() {
return gulp.src('./css/theme.css') return gulp.src('./css/theme.css')
.pipe(cleanCSS({compatibility: 'ie8'})) .pipe(cleanCSS({compatibility: 'ie8'}))
.pipe(plumber()) .pipe(plumber({
errorHandler: function (err) {
console.log(err);
this.emit('end');
}
}))
.pipe(rename({suffix: '.min'})) .pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./css/')); .pipe(gulp.dest('./css/'));
}); });