Glob/minimatch:如何 gulp.src() 一切,然后排除文件夹但在其中保留一个文件 [英] Glob / minimatch: how to gulp.src() everything, then exclude folder but keep one file in it

查看:22
本文介绍了Glob/minimatch:如何 gulp.src() 一切,然后排除文件夹但在其中保留一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的项目:

root
  |-incl1
  |-incl2
  |- ...
  |-excl1
  |-excl2
     |- .gitignore  <-- keep this one
     |- (other files)  <-- exclude them

我需要编写 gulp.src(),它将包括除 excl1excl2 but 之外的所有文件夹保留 .gitignore 文件.

I need to write gulp.src() that will include all folders except excl1 and excl2 but keep the .gitignore file.

这是我的代码不起作用:

This is my code that doesn't work:

gulp.src([
  baseDir + '/**',
  '!' + baseDir + '/{excl1, excl1/**}'
  '!' + baseDir + '/excl2/{**, !.gitignore}'  // <-- doesn't work
], {dot: true})

推荐答案

这似乎可行:

gulp.src([
    baseDir + '/**',                              // Include all
    '!' + baseDir + '/excl1{,/**}',               // Exclude excl1 dir
    '!' + baseDir + '/excl2/**/!(.gitignore)',    // Exclude excl2 dir, except .gitignore
], { dot: true });

从全局匹配中排除单个文件很棘手,因为在 minimatch 文档中没有类似的示例.

Excluding single file from glob match was tricky because there's no similar examples in minimatch docs.

https://github.com/isaacs/minimatch

如果模式以 ! 字符开头,则它被否定".

"If the pattern starts with a ! character, then it is negated".

这篇关于Glob/minimatch:如何 gulp.src() 一切,然后排除文件夹但在其中保留一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆