【问题标题】:Gulp Watch Not calling associated gulp taskGulp Watch 不调用关联的 gulp 任务
【发布时间】:2016-11-02 05:47:10
【问题描述】:

所以我在(长时间的)休息后回到了个人项目,我又回到了事情的流程中。打我脸的一件事是我的观察者没有工作。例如,如果我调用 gulp watch-for-jshint,我希望 JSHint 在我修改 JS 文件时随时更改——无论是根文件 (gulp.js) 还是我的客户端应用程序文件之一 (./client-app/js /controllers/register.js)。那没有发生。我可以看到手表正在启动,但是当我更改文件时它从不调用 JSHint!

有人知道出了什么问题或如何诊断吗?据我所知,我的语法是正确的......而且因为(出于测试目的)我直接调用了 watch-for-jshint,我应该避免通常的陷阱,即从不真正调用我的观察者。

简化的 gulp 文件:

var gulp = require('gulp'),
  clean = require('gulp-clean'),
  jshint = require('gulp-jshint'),
  notify = require('gulp-notify'),
  watch = require('gulp-watch'),

gulp.task('jshint', function(){
  console.log("Running JSHint");
  return gulp.src(['*.js', 'client-app/**/*.js'], ['jshint'])
    .pipe(jshint({"moz":true}))
    .pipe(jshint.reporter('default'))
    .pipe(jshint.reporter('fail'))
    .on('error', notify.onError({ sound: "Funk" }));
});

gulp.task('watch-for-jshint', function(){
  return watch(['*.js', './client-app/**/*.js'], ['jshint']);
});

我已经截断了很多无关的任务,但上面的内容应该是所有相关的。

【问题讨论】:

    标签: javascript gulp gulp-watch


    【解决方案1】:

    自然地,在发布 5 分钟后,我注意到我的语法与许多问题使用的语法之间存在一个差异。大多数人都在使用gulp.watch,我只是按照gulp-watch NPM module页面上的语法使用watch

    不...完全确定为什么一个有效而另一个无效;奇怪的。似乎新版本不应该工作,因为它没有引用 gulp-watch 模块。

    【讨论】:

      【解决方案2】:

      如果不需要,删除 gulp 任务中的以下行。

      .on('error', notify.onError({ sound: "Funk" }))

      这会使 gulp 任务停止并显示错误。因此手表也停止了。

      替换

      return watch(['*.js', './client-app/**/*.js'], ['jshint']);

      gulp.watch(['*.js', './client-app/**/*.js'], ['jshint']);

      【讨论】:

        猜你喜欢
        • 2015-03-11
        • 2015-07-14
        • 1970-01-01
        • 2018-01-01
        • 2016-06-04
        • 1970-01-01
        • 1970-01-01
        • 2023-04-09
        • 1970-01-01
        相关资源
        最近更新 更多