在gulp.watch中排除子目录

16

我想深入查看模板中所有嵌套的文件,但排除build文件夹之后的任何文件夹。

因此排除以下目录:

  • ./templates/foo/build/**/*

  • ./templates/bar/build/**/*

包括以下目录和文件:

  • ./templates/foo/template.html

  • ./templates/foo/css/**/*

  • ./templates/bar/template.html

  • ./templates/bar/css/**/*

目前我正在成功列举子子文件夹名称和子子文件类型。

gulp.watch(['templates/*/*.html','templates/*/*.js',
            'templates/*/*.json','templates/*/css/**/*',
            'templates/*/js/**/*'], ['build_templates']);

但是我真的希望能够停止每次添加特定的子子文件夹或子子文件类型时更新表达式。如何包括除此之外的所有内容?

2个回答

22

我认为你可以尝试使用 ! 符号来排除 build 子目录。

可以参考以下示例,根据自己的需求进行调整:

gulp.watch([
 'templates/**/*',
 '!templates/*/{build,build/**}'
], ['build_templates'])

你也可以查看Gulp Ignore


我无法让它正常工作。我找到了https://www.npmjs.org/package/gulp-grep-stream。 - jrhicks
1
@SachinGorade 错了,你不需要插件来否定全局模式。 - Preview
@Aperçu 我在没有安装 Gulp Ignore 的情况下尝试它时,它不起作用。 - Sachin Gorade
对于未来的读者,否定的全局模式应该放在最后一个索引上,顺序可能会影响结果。 - StefansArya

6

我知道这已经有点过时了,但是您应该将文件夹以及文件夹里面的所有内容都排除掉,仅仅排除文件夹本身是不起作用的。

gulp.watch(['templates/**/*','!templates/{foo, bar}/build/**/*'], ['build_templates']);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接