Skip to content

Instantly share code, notes, and snippets.

@jonathanpglick
Last active June 27, 2016 23:27
Show Gist options
  • Save jonathanpglick/5dbea90a81c70cc66c15f5d9af00e93e to your computer and use it in GitHub Desktop.
Save jonathanpglick/5dbea90a81c70cc66c15f5d9af00e93e to your computer and use it in GitHub Desktop.
Handling LESS errors in Gulpfile
// 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