在按照记录的示例后,我无法点击gulp-watch或gulp-watch-less。我最初的问题是lazypipe(这里没有显示),但在我看来,我在使用插件的方式上做错了。这是我愚蠢的代码,但仍无效。
请注意,我尝试使用普通的gulp-watch,它表现出完全相同的问题:它不会在更改时触发后续管道。如果出现问题,我会在这里附上信息。
这是我的gulpfile。
var debug = require ( 'gulp-debug' );
var gulp = require ( 'gulp' );
var less = require ( 'gulp-less' );
var watchLess = require ( 'gulp-watch-less' );
gulp.task ( 'dev-watch', function () {
// main.less just imports child less files
gulp.src ( './app/styles/less/main.less' )
.pipe ( watchLess ( './app/styles/less/main.less' ) )
.pipe ( debug () );
.pipe ( less () )
.pipe ( gulp.dest ( './app/styles' ) )
;
});
当我开始任务时,它会执行并完美地生成预期的文件。我看到调试输出流信息也很好。
当我更改文件时,我发现watchLess正在接受更改:
[10:49:54] LESS saw child.less was changed
[10:49:54] LESS saw child.less was changed
[10:49:54] LESS saw main.less was changed:by:import
[10:49:54] LESS saw main.less was changed:by:import
但是,较少的任务不会执行。它似乎没有发出任何东西,因为调试不会触发。
这是相关的package.json信息:
"devDependencies": {
"gulp": "^3.8.7",
"gulp-less": "^1.3.6",
"gulp-watch": "^1.2.0",
"gulp-watch-less": "^0.2.1"
}
答案 0 :(得分:1)
您的代码仅在管道中运行观察程序,但不会告诉您该怎么做。
工作示例应如下:
var
gulp = require('gulp'),
debug = require ('gulp-debug'),
less = require ( 'gulp-less'),
watchLess = require('gulp-watch-less');
gulp.task('dev-watch', function () {
watchLess('./app/styles/less/main.less')
.pipe (debug ())
.pipe(less())
.pipe(gulp.dest('./app/styles'))
});
但是,您也可以使用gulp-watch或gulp(gulp.watch)来做同样的事情。
答案 1 :(得分:0)
这一定是最好的解决方案,我在gulp-less github中获得自述文件;
https://github.com/plus3network/gulp-less
https://github.com/gulpjs/gulp/blob/master/docs/recipes/combining-streams-to-handle-errors.md npm i stream-combiner2 --save-dev
var combiner = require('stream-combiner2');
var combined = combiner.obj([
gulp.src(srcs),
less(),
autoprefixer({
browsers: ['last 6 versions'],
cascade: false
}),
isDev ? null : cleanCss(),
gulp.dest(targetDir + 'css/multi/'),
].filter(v => v));
// any errors in the above streams will get caught
// by this listener, instead of being thrown:
combined.on('error', console.error.bind(console));
combined.on('end', () => {}); //done have been call when return combined;
return combined;