简体   繁体   English

gulp-watch,gulp-watch-less不要开火

[英]gulp-watch, gulp-watch-less don't fire

I'm having trouble getting gulp-watch or gulp-watch-less to fire after following the documented examples. 按照记录在案的例子后,我无法通过gulp-watchgulp-watch-less来解决问题。 I originally through the problem was with lazypipe (not shown here), but it appears to me that I'm doing something wrong in the way I'm using the plugins. 我最初的问题是lazypipe(这里没有显示),但在我看来,我在使用插件的方式上做错了。 Here's my dumbed-down code which is still not working. 这是我愚蠢的代码仍然无法正常工作。

Note that I tried this with plain gulp-watch and it exhibits the exact same issue: it doesn't trigger subsequent pipes on change. 请注意,我尝试使用普通的gulp-watch,它表现出完全相同的问题:它不会在更改时触发后续管道。 I'll include info around that here in case that's the problem. 如果出现问题,我会在这里附上信息。

Here's my gulpfile. 这是我的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' ) )
  ;
});

When I start the task, it executes and generates the expected files perfectly. 当我启动任务时,它会执行并完美地生成预期的文件。 I see debug output the stream info just fine as well. 我看到调试输出流信息也很好。

When I change a file I see that watchLess is picking up the change: 当我更改文件时,我看到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

However, the less task doesn't execute. 但是,较少的任务不会执行。 It doesn't appear to be emitting anything because debug doesn't fire. 它似乎没有发出任何东西,因为调试不会触发。

Here's the pertinent package.json info: 这是相关的package.json信息:

"devDependencies": {
  "gulp": "^3.8.7",
  "gulp-less": "^1.3.6",
  "gulp-watch": "^1.2.0",
  "gulp-watch-less": "^0.2.1"
}

Your code merely runs the watcher in pipe, but does not tell what to do then. 您的代码仅在管道中运行观察程序,但不会告诉您该怎么做。

The working example should be the following: 工作示例应如下:

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'))
});

However, you can also do the same thing using merely gulp-watch or gulp (gulp.watch). 但是,您也可以使用gulp-watch或gulp(gulp.watch)来做同样的事情。

this must be the best solution, and I get in readme in gulp-less github; 这一定是最好的解决方案,我在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 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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM