Glob / minimatch: how to gulp.src() everything, then exclude folder but keep one file in it

后端 未结 1 1298
抹茶落季
抹茶落季 2020-12-14 01:35

I have a project like this:

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


        
相关标签:
1条回答
  • 2020-12-14 01:51

    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".

    0 讨论(0)
提交回复
热议问题