我有一个非常小的gulp文件如下,注册了一个手表任务:
var gulp = require("gulp");
var jshint = require("gulp-jshint");
gulp.task("lint",function() {
gulp.src("app/assets/**/*.js")
.pipe(jshint())
.pipe(jshint.reporter("default"));
});
gulp.task('watch',function() {
gulp.watch("app/assets/**/*.js",["lint"]);
});
我无法让观看任务持续运行.一旦我运行gulp手表,它立即终止.
我已经清除了我的npm缓存,重新安装依赖关系等,但没有骰子.
$gulp watch [gulp] Using gulpfile gulpfile.js [gulp] Starting 'watch'... [gulp] Finished 'watch' after 23 ms
解决方法
这不是现在,这是
running the task synchronously.
您需要从lint任务返回流,否则gulp不知道该任务何时完成.
gulp.task("lint",function() {
return gulp.src("./src/*.js")
^^^^^^
.pipe(jshint())
.pipe(jshint.reporter("default"));
});
此外,您可能不想使用gulp.watch和这种手表的任务.使用the gulp-watch plugin可能更有意义,因此您只能处理更改的文件,类似于此:
var watch = require('gulp-watch');
gulp.task('watch',function() {
watch({glob: "app/assets/**/*.js"})
.pipe(jshint())
.pipe(jshint.reporter("default"));
});
这个任务不仅会在文件发生变化时发生,而且还会添加任何新添加的文件.