tec*_*000 6 javascript eslint gulp gulp-watch
我正在和gulp一起尝试.我已经设置了这样的任务:
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());
});
Run Code Online (Sandbox Code Playgroud)
当我跑的时候gulp lint
它告诉我很多错误.现在我试图逐一修复它们.但是我必须gulp lint
手动重新运行才能给我一个更新的报告.如何设置它以便每次更新时它都会自动重新运行'components/myjs.js'
?
只需添加一个监视任务:
gulp.task('watch', function() {
gulp.watch('components/myjs.js', ['lint']);
});
Run Code Online (Sandbox Code Playgroud)
这样,Gulp将跟踪您的任何变化,'components/myjs.js'
并'lint'
在任何变更时执行您的任务
如果您想进一步阅读:https: //scotch.io/tutorials/automate-your-tasks-easily-with-gulp-js