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
This commit is contained in:
25
gulpfile.js
25
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'));
|
||||
|
||||
Reference in New Issue
Block a user