为什么gulp jshint任务执行两次?

时间:2014-05-29 06:40:12

标签: gulp

这是gulpfile.js:

var gulp    = require('gulp'),
    jshint  = require('gulp-jshint'),
    connect = require('gulp-connect');

gulp.task('jshint', function(){
  gulp.src('app/scripts/*.js')
      .pipe(jshint('.jshintrc'))
      .pipe(jshint.reporter('jshint-stylish'));
});

gulp.task('html', function(){
  gulp.src('app/index.html')
      .pipe(connect.reload());
});

gulp.task('watch', function(){
  gulp.watch('app/index.html', ['html']);

  gulp.watch('app/scripts/*.js', ['jshint']);
});

gulp.task('serve', function(){
  connect.server({
    root: 'app',
    port: '9001',
    livereload: true
  });
});

gulp.task('default', ['jshint', 'serve', 'watch']);

当我编辑app/scripts/*.js时,jshint任务将运行两次。为什么?我gulpfile.js中有什么问题吗?

感谢。

1 个答案:

答案 0 :(得分:0)

似乎您的默认任务是负责任的。

它执行jshing任务(到目前为止1次),然后执行任务(ok)并最终观察,这将再次执行jshint。

如果你已经将jshint传递给你的文件,也许你应该从默认的任务中删除jshint任务,并创建另一个没有观看的任务,所以你只执行一次该任务,你就可以只看新文件了。 / p>