这是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
中有什么问题吗?
感谢。
答案 0 :(得分:0)
似乎您的默认任务是负责任的。
它执行jshing任务(到目前为止1次),然后执行任务(ok)并最终观察,这将再次执行jshint。
如果你已经将jshint传递给你的文件,也许你应该从默认的任务中删除jshint任务,并创建另一个没有观看的任务,所以你只执行一次该任务,你就可以只看新文件了。 / p>