排除gulp.watch中的子目录

Exclude sub-directory in gulp.watch

本文关键字:子目录 watch gulp 排除      更新时间:2023-09-26

我想看到所有的文件深嵌套在模板中,但排除任何文件夹后构建。

所以排除目录,如:

  • 。/模板/foo/构建/* */*

  • 。/模板/酒吧/构建/* */*

包含目录和文件,如:

  • 。/模板/foo/template.html

  • 。/模板/foo/css/* */*

  • 。/模板/酒吧/template.html

  • 。/模板/酒吧/css/* */*

目前我已经成功地列出了子文件夹名称和子文件类型

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

但是我真的希望能够在每次添加特定的子-子文件夹或子-子-文件类型时停止更新表达式。怎么能包括一切?

我认为您可以尝试排除!符号的build子目录。

想想这样的东西,使它适合你的需要:

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

你也可以看看Gulp Ignore

我知道这是旧的,但是你应该排除文件夹和文件夹中的所有东西,单独排除文件夹是行不通的。

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