2014-05-19 54 views
4

我有一个简单的默认任务的掉毛改变js文件:如何将gulp.watch()传递给管道?

gulp.task('default', function() { 
     // watch for JS changes 
     gulp.watch(base + 'javascripts/**/*.js', function() { 
      gulp.run('jshint'); 
     }); 
    }); 

的问题是,jshint任务再次源文件:

gulp.task('jshint', function() { 
     gulp.src([base + 'javascripts/*.js']) 
      .pipe(jshint()) 
      .pipe(jshint.reporter('default')); 
    }); 

什么情况是,所有文件LINTED ,不仅是变化的。

有没有办法只将更改的文件传递给jshint?

+0

姆姆。感觉尴尬,因为改变()需要一个我不需要的目的地,因为没有任何东西正在改变。似乎有点反对围绕吞咽的易用性炒作? – andig

+2

不要使用'gulp.watch'进行渐进式工作,[请使用'gulp-watch'插件](https://www.npmjs.org/package/gulp-watch) – OverZealous

回答

2

根据@OverZealous我发现这种方法使用gulp-watch工作:

gulp.task('default', function() { 
    gulp.src(base + 'javascripts/**/*.js', { read: false }) 
     .pipe(watch()) 
     .pipe(jshint()) 
     .pipe(jshint.reporter('default')); 
}); 

{ read: false }需要避免掉毛启动时的所有文件。 此解决方案不会而不是首次启动时不存在的lint文件。

相关问题