From ad4523fef62322ad846f0e08a50978818416311c Mon Sep 17 00:00:00 2001 From: Austin Pray Date: Mon, 23 Feb 2015 15:11:06 -0600 Subject: [PATCH] fix less breaking during watch on error If the `--production` flag is set: hard fail the build if there is a precompiler error. If unset, log an error and end the task successfully. fixes https://github.com/roots/roots/issues/1288 --- gulpfile.js | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 04e3023510..e2d75851c0 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -42,7 +42,9 @@ var enabled = { // Enable static asset revisioning when `--production` rev: argv.production, // Disable source maps when `--production` - maps: !argv.production + maps: !argv.production, + // Fail styles task on error when `--production` + failStyleTask: argv.production }; // Path to the compiled assets manifest in the dist directory @@ -60,21 +62,21 @@ var revManifest = path.dist + 'assets.json'; // ``` var cssTasks = function(filename) { return lazypipe() - .pipe($.plumber) + .pipe(function() { + return $.if(!enabled.failStyleTask, $.plumber()); + }) .pipe(function() { return $.if(enabled.maps, $.sourcemaps.init()); }) .pipe(function() { - return $.if('*.less', $.less().on('error', function(err) { - console.warn(err.message); - })); + return $.if('*.less', $.less()); }) .pipe(function() { return $.if('*.scss', $.sass({ outputStyle: 'nested', // libsass doesn't support expanded yet precision: 10, includePaths: ['.'], - onError: console.error.bind(console, 'Sass error:') + errLogToConsole: !enabled.failStyleTask })); }) .pipe($.concat, filename) @@ -137,11 +139,20 @@ var writeToManifest = function(directory) { // ### Styles // `gulp styles` - Compiles, combines, and optimizes Bower CSS and project CSS. +// By default this task will only log a warning if a precompiler error is +// raised. If the `--production` flag is set: this task will fail outright. gulp.task('styles', ['wiredep'], function() { var merged = merge(); manifest.forEachDependency('css', function(dep) { + var cssTasksInstance = cssTasks(dep.name); + if (!enabled.failStyleTask) { + cssTasksInstance.on('error', function(err) { + console.error(err.message); + this.emit('end'); + }); + } merged.add(gulp.src(dep.globs, {base: 'styles'}) - .pipe(cssTasks(dep.name))); + .pipe(cssTasksInstance)); }); return merged .pipe(writeToManifest('styles'));