gpt4 book ai didi

css - 当文件中遇到较少的错误时,Gulp-less watcher 会中断

转载 作者:行者123 更新时间:2023-11-28 06:23:26 25 4
gpt4 key购买 nike

我想看一个文件少的文件夹。当其中一个被更改时,我只想编译“styles.less”文件(这个文件包含@imports到其余文件,如“header.less”,“navigation.less”等)为此,我创建了 2 个任务。当我运行“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
});

关于css - 当文件中遇到较少的错误时,Gulp-less watcher 会中断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35421332/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com