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

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

问题描述

我有这样一个项目:

  root 
| -incl1
| -incl2
| - ...
| -excl1
| -excl2
| - .gitignore< - 保留这一个
| - (其他文件)< - - 排除它们

我需要编写 gulp.src()将包括除 excl1 和 excl2 以外的所有文件夹 .gitignore 文件。



这是我的代码,不起作用:

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


解决方案

这似乎起作用:

  gulp.src([
baseDir +'/ **',//包含所有
'!'+ baseDir +'/ excl1 {,/ **}',//排除excl 1 dir
'!'+ baseDir +'/excl2/**/!(.gitignore)',//排除excl2目录,但.gitignore
,{dot:true});

从glob匹配中排除单个文件非常棘手,因为minimatch文档中没有类似的示例。



https://github.com/isaacs/minimatch



如果模式以字符开头,则它被否定。

I have a project like this:

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

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})

解决方案

This seems to work:

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

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天全站免登陆