2016-02-15 33 views
0

我想觀察文件較少的文件夾。當其中一個改變時,我想只編譯「styles.less」文件(該文件包含@imports到其他文件,如「header.less」,「navigation.less」等) 爲此,我創建了2個任務。當我運行任務「不守規矩」時,一切正常,它將styles.less編譯爲styles.css。但是,如果出現錯誤,當我編輯一個較少的文件時,觀察者即使用吞嚥水管工也會中斷。我怎樣才能解決這個問題?在文件中遇到較少錯誤時,無人值守觀察者會中斷

var gulp = require('gulp'); 
var plumber = require('gulp-plumber'); 
var less = require('gulp-less'); 
var watch = require('gulp-watch'); 

var path_less = 'templates/responsive/css/less/'; 
var path_css = 'templates/responsive/css/'; 

gulp.task('less2css', function() { 
    return gulp.src(path_less + 'styles.less') 
     .pipe(plumber()) 
     .pipe(less()) 
     .pipe(gulp.dest(path_css)) 
}); 

gulp.task('watchless', function() { 
    gulp.watch(path_less + '*.less', ['less2css']); // Watch all the .less files, then run the less task 
}); 

回答

0

最後,它的工作,使用下面的代碼:

var gulp = require('gulp'); 
var gutil = require('gulp-util'); 
var less = require('gulp-less'); 
var watch = require('gulp-watch'); 

var path_less = 'templates/responsive/css/less/'; 
var path_css = 'templates/responsive/css/'; 

gulp.task('less2css', function() { 
    gulp.src(path_less + 'styles.less') 
     .pipe(less().on('error', gutil.log)) 
     .pipe(gulp.dest(path_css)) 
}); 

gulp.task('watchless', function() { 
    gulp.watch(path_less + '*.less', ['less2css']); // Watch all the .less files, then run the less task 
});