Gulp-less watcher 在文件中遇到 less 错误时中断
Gulp-less watcher breaks when a less error is encountered in a file
我想看一个文件少的文件夹。当其中一个被更改时,我只想编译 "styles.less" 文件(此文件包含 @imports 到其余文件,如 "header.less"、"navigation.less" 等)
为此,我创建了 2 tasks.When i 运行 任务 "watchless",一切正常,它将 styles.less 编译为 styles.css。但是,如果遇到错误,当我编辑一个 less 文件时,即使使用 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
});
我想看一个文件少的文件夹。当其中一个被更改时,我只想编译 "styles.less" 文件(此文件包含 @imports 到其余文件,如 "header.less"、"navigation.less" 等) 为此,我创建了 2 tasks.When i 运行 任务 "watchless",一切正常,它将 styles.less 编译为 styles.css。但是,如果遇到错误,当我编辑一个 less 文件时,即使使用 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
});