我正在和gulp一起尝试eslint。我已经设置了这样的任务:
gulp.task('lint', function () {
return gulp.src([
'components/myjs.js'
])
// eslint() attaches the lint output to the eslint property
// of the file object so it can be used by other modules.
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failOnError last.
.pipe(eslint.failOnError());
});
当我运行gulp lint
时
它告诉我很多错误。现在我试图逐一修复它们。但是我必须手动重新运行gulp lint
才能给我一个更新的报告。如何设置它以便每次更新'components/myjs.js'
时都会自动重新运行?
答案 0 :(得分:8)
只需添加监视任务:
gulp.task('watch', function() {
gulp.watch('components/myjs.js', ['lint']);
});
通过这种方式,Gulp会跟踪'components/myjs.js'
上的所有更改,并在任何更改时执行'lint'
任务
如果您想进一步阅读: https://scotch.io/tutorials/automate-your-tasks-easily-with-gulp-js