我想看一个文件较少的文件夹。当其中一个被更改时,我只想编译"styles.less"文件(该文件包含对其余文件的@imports,如"header.less","navigation.less"等(为此,我创建了 2 个任务。当我运行任务"无监视"时,一切都很好,它将 styles.less 编译为 styles.css。但是,如果遇到错误,当我编辑较少的文件时,即使使用gulp-plumber,观察程序也会中断。我该如何解决这个问题?
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
});
最后,它使用以下代码工作:
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
});