6

我正在用 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'

4

1 回答 1

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

于 2015-04-27T20:41:45.500 回答