Last active
June 27, 2016 23:27
-
-
Save jonathanpglick/5dbea90a81c70cc66c15f5d9af00e93e to your computer and use it in GitHub Desktop.
Handling LESS errors in Gulpfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Less tasks used to look like this: | |
gulp.task('screen-less', function() { | |
return gulp.src('css/screen.less') | |
.pipe(plumber()) | |
.pipe(less()) | |
.pipe(gulp.dest('./css/')) | |
.pipe(livereload()); | |
}); | |
// We need to add a function to `plumber()` that will gracefully handle errors without exiting the parent `watch` task. | |
// This is what the function would look like: | |
function plumberConfig(error) { | |
console.log(error); | |
this.emit('end'); | |
this.destroy(); | |
} | |
// And used: | |
gulp.task('screen-less', function() { | |
return gulp.src('css/screen.less') | |
.pipe(plumber(plumberConfig)) | |
.pipe(less()) | |
.pipe(gulp.dest('./css/')) | |
.pipe(livereload()); | |
}); | |
// Or inlined: | |
gulp.task('screen-less', function() { | |
return gulp.src('css/screen.less') | |
.pipe(plumber(function (error) { | |
console.log(error); | |
this.emit('end'); | |
this.destroy(); | |
})) | |
.pipe(less()) | |
.pipe(gulp.dest('./css/')) | |
.pipe(livereload()); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment