您的代码仅在管道中运行观察程序,但不会告诉您该怎么做。
工作示例应如下:
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)来做同样的事情。
这一定是最好的解决方案,我在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
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;