我已经定义了一些任务gulpfile.js
,我想使用gulp-watch
插件(在新文件上运行任务)。我的问题是,因为我找不到任何东西,我可以在运行手表(来自插件)功能的同时运行我现有的任务吗?
var gulp = require('gulp'),
watch = require('gulp-watch'),
...;
gulp.task('lint', function () {
return gulp.src(path.scripts)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
});
gulp.task('watch', function () {
watch({ glob: 'app/**/*.js' }); // Run 'lint' task for those files
});
因为我不想watch()
在我拥有的每项任务中都包含任务。我只想有一项任务 - 手表,它将结合所有“手表”。
----- 编辑----(因为我可能不太明白我的意思):
我需要从任务内部运行gulp('watch')
任务。例如:
就像我这样做gulp.watch
:
gulp.task('watch', function () {
gulp.watch('files', ['task1', 'task2']);
});
我需要做同样的事情,但使用gulp-watch
插件,比如(我知道它不起作用):
var watch = require('gulp-watch');
gulp.task('watch', function () {
watch({ glob: 'files' }, ['task1', 'task2']);
});