Merge pull request #1342 from austinpray/fixWatch

fix less breaking during watch on error
This commit is contained in:
Ben Word
2015-02-23 19:06:39 -06:00

View File

@@ -42,7 +42,9 @@ var enabled = {
// Enable static asset revisioning when `--production` // Enable static asset revisioning when `--production`
rev: argv.production, rev: argv.production,
// Disable source maps when `--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 // Path to the compiled assets manifest in the dist directory
@@ -60,21 +62,21 @@ var revManifest = path.dist + 'assets.json';
// ``` // ```
var cssTasks = function(filename) { var cssTasks = function(filename) {
return lazypipe() return lazypipe()
.pipe($.plumber) .pipe(function() {
return $.if(!enabled.failStyleTask, $.plumber());
})
.pipe(function() { .pipe(function() {
return $.if(enabled.maps, $.sourcemaps.init()); return $.if(enabled.maps, $.sourcemaps.init());
}) })
.pipe(function() { .pipe(function() {
return $.if('*.less', $.less().on('error', function(err) { return $.if('*.less', $.less());
console.warn(err.message);
}));
}) })
.pipe(function() { .pipe(function() {
return $.if('*.scss', $.sass({ return $.if('*.scss', $.sass({
outputStyle: 'nested', // libsass doesn't support expanded yet outputStyle: 'nested', // libsass doesn't support expanded yet
precision: 10, precision: 10,
includePaths: ['.'], includePaths: ['.'],
onError: console.error.bind(console, 'Sass error:') errLogToConsole: !enabled.failStyleTask
})); }));
}) })
.pipe($.concat, filename) .pipe($.concat, filename)
@@ -137,11 +139,20 @@ var writeToManifest = function(directory) {
// ### Styles // ### Styles
// `gulp styles` - Compiles, combines, and optimizes Bower CSS and project CSS. // `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() { gulp.task('styles', ['wiredep'], function() {
var merged = merge(); var merged = merge();
manifest.forEachDependency('css', function(dep) { 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'}) merged.add(gulp.src(dep.globs, {base: 'styles'})
.pipe(cssTasks(dep.name))); .pipe(cssTasksInstance));
}); });
return merged return merged
.pipe(writeToManifest('styles')); .pipe(writeToManifest('styles'));