0

我想看一个文件较少的文件夹。当其中一个发生更改时,我只想编译“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
});
4

1 回答 1

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
});
于 2016-02-16T15:16:49.947 回答