Miomir Dancevic
Miomir Dancevic

Reputation: 6852

Gulp watch less and error?

I am using gulp for creating some css from less and have watch function. Everything working ok when there is no errors in less files, watch is calling less function and compile css. But when i have errors in less files, watch just breaks say where is error stop. When i fix error in less file, watch does not work anymore. I have to start it again, is it possible to see if there is error and just continue watching for compiling, here is my gulp.js

// Less to CSS task
var parentPath = './content/css/';
var sourceLess = parentPath;
var targetCss = parentPath;

gulp.task('less', function () {
    return gulp.src([sourceLess + 'styles.less'])
        .pipe(less({ compress: true }).on('error', gutil.log))
        .pipe(autoprefixer('last 10 versions', 'ie 9'))
        .pipe(minifyCSS({ keepBreaks: false }))
        .pipe(gulp.dest(targetCss))
        .pipe(notify('Less Compiled, Prefixed and Minified'));
});

gulp.task('watch', function () {
    gulp.watch([sourceLess + 'styles.less'], ['less']);  // Watch all the .less files, then run the less task
});

Upvotes: 0

Views: 201

Answers (1)

franmartosr
franmartosr

Reputation: 388

In gulp-less plugin documentation says that it doesn't have a built-in way to fail the task and keep the watcher active. But it says that you can't do it with stream-combiner2.

You can see the example here taked from the official gulp github repo.

Upvotes: 0

Related Questions