Gulp watch:根据event.type有条件地运行任务

Gulp watch: Conditionally run tasks dependent on event.type

本文关键字:有条件 运行 任务 type event watch 根据 Gulp      更新时间:2023-09-26

我得到了以下内容:

gulp.watch('src/**/*', ['compile']);
gulp.watch('src/**/*', (event) => {
  if (event.type === 'deleted' {
    gulp.src(event.path.replace('src/', 'compiled/')).pipe(clean());
  } else {
    // TODO: Only run 'compile' when file is not deleted.
  }
});

每当添加或修改文件时,我想运行compile任务,它将获取新文件并将其移动到编译目录中。

当一个文件被删除时,我不想运行compile任务,因为它什么也不做。相反,我需要从编译目录中删除该文件。

上面的代码可以工作,但是在删除文件时继续运行编译任务(导致no-op)。

如何有条件地运行另一个任务?看起来runstart Gulp方法都已被删除和/或弃用。

你可以在你的任务中包含{read: false}

gulp.task('default', function () {
    return gulp.src('app/tmp', {read: false})
        .pipe(clean());