我有两个任务,它们是“样式”和“干净样式”。监视任务监视 .less 文件中的任何更改,并在发现更改时触发样式任务。这个场景工作正常。
当 .less 中存在语法错误时,gulp-plumber 会在 cmd 行上显示错误,其余的执行也会停止,这也是正确的。
纠正 .less 中的错误后,watch 恢复并触发了样式任务,但样式任务只是完成了依赖的 clean-styles 任务,没有进一步的进展。
我还希望执行样式任务。请帮忙。
gulp.task('styles', ['clean-styles'], function () {
config.log('Less -> CSS compilation in progress... [gulp-inject, gulp-less, autoprefixer]');
var partialLessfiles = gulp.src(
[
path.join(config.paths.styles, '**/*.less'),
path.join('!' + config.paths.styles, 'index.less')
],
{read: false}
).pipe(print());
return gulp.src([path.join(config.paths.styles, 'index.less')])
.pipe(inject(partialLessfiles, injectOptions))
.pipe(plumber())
.pipe(less())
.pipe(autoprefixer())
.pipe(gulp.dest(config.paths.temp));
});
gulp.task('clean-styles', function() {
config.log('Deleting all styles from .tmp in progress...');
var files = config.paths.temp + '**/*.css';
config.clean(files);
});
config.clean = function(path) {
util.log('Deleting ' + path);
del(path);
};
gulp.task('less-watcher', function() {
config.log('Watching for any changes in .less files... [watch]');
gulp.watch([config.paths.allless], ['styles']);
});