我想观看较少文件的文件夹。当其中一个被更改时,我想只编译“styles.less”文件(这个文件包含@imports到其他文件,如“header.less”,“navigation.less”等) 为此,我创建了2个任务。当我运行任务“无视”时,一切正常,它编译样式。没有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 :(得分: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
});