javascript 排除 gulp.watch 中的子目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24834463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 03:25:15  来源:igfitidea点击:

Exclude sub-directory in gulp.watch

javascriptnode.jsgulp

提问by jrhicks

I would like to watch all files deeply nested within templates but exclude any folder after build.

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

So excludedirectories like:

所以排除目录,如:

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

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

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

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

But includedirectories and files like:

包括目录和文件,如:

  • ./templates/foo/template.html

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

  • ./templates/bar/template.html

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

  • ./templates/foo/template.html

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

  • ./templates/bar/template.html

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

Currently I am having success itemizing the sub-sub-folder names and sub-sub-filetypes

目前我正在成功地逐项列出子文件夹名称和子子文件类型

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

But I would really like to be able to stop updating the expression every time I add specific sub-sub-folders or sub-sub-filetypes. How can include everything except?

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

回答by Balthazar

I think that you could try to do exclude the buildsub directories with the !sign.

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

Think of something like this, adapt it to fits your needs :

想想这样的事情,使其适应您的需求:

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

You could also have a look to Gulp Ignore.

你也可以看看Gulp Ignore

回答by Bamieh

I know this is old, but you should exclude the folder andeverything inside the folder aswell, excluding the folder alone doesnt work.

我知道这是旧的,但是您应该排除文件夹文件夹内的所有内容,单独排除文件夹是行不通的。

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