如何使用gulp watch中的参数运行gulp任务?

如何使用gulp watch中的参数运行gulp任务?,gulp,gulp-watch,Gulp,Gulp Watch,我有一个像这样的怀表: gulp.watch(somepath, {interval: 500}, ['buildScripts']); gulp.task('buildScripts', function (path) { //compiles the file from watch }); 构建脚本如下所示: gulp.watch(somepath, {interval: 500}, ['buildScripts']); gulp.task('buildScripts', fun

我有一个像这样的怀表:

gulp.watch(somepath, {interval: 500}, ['buildScripts']);
gulp.task('buildScripts', function (path) {
   //compiles the file from watch
});
构建脚本如下所示:

gulp.watch(somepath, {interval: 500}, ['buildScripts']);
gulp.task('buildScripts', function (path) {
   //compiles the file from watch
});

如何传递已更改文件的值,以便
构建脚本
可以编译这些文件?

您必须将
构建脚本
代码分解为自己的函数,并从手表和任务中调用该函数。如果你不需要这项任务,你当然可以放弃它

var gulp = require('gulp');

function buildScripts(changedFile) {
  if (changedFile) {
    // called from watch
    // compile the changed file
  } else {
    // called from task
    // compile all files
  }
}

gulp.task('buildScripts', function() {
  return buildScripts();
});

gulp.task('watch', function() {
  gulp.watch('*.js', {interval:500}, buildScripts);
});

您必须将
buildScripts
代码分解成它自己的函数,并从手表和任务中调用该函数。如果你不需要这项任务,你当然可以放弃它

var gulp = require('gulp');

function buildScripts(changedFile) {
  if (changedFile) {
    // called from watch
    // compile the changed file
  } else {
    // called from task
    // compile all files
  }
}

gulp.task('buildScripts', function() {
  return buildScripts();
});

gulp.task('watch', function() {
  gulp.watch('*.js', {interval:500}, buildScripts);
});