包括目录中的所有内容但只有一件事

时间:2014-07-25 14:52:01

标签: gruntjs

我想在一个目录上运行grunt-contrib-concat并匹配其中的所有内容,除了一个子目录,但是,在该子目录中我想匹配一个文件。所以它看起来像这样:

// Include everything
topDir/

// Include only one file in this specific directory
topDir/**/subdir/onlyIncludeThisFromThisDirectory.whatever

有一种简单的方法吗?

1 个答案:

答案 0 :(得分:0)

这很容易:

[
  'topDir/**/*.whatevet',
  '!topDir/**/subdir/**/*',
  'topDir/**/subdir/onlyIncludeThisFromThisDirectory.whatever']`
]

带有前导!的模式是excluding pattern。 请记住,在使用"文件数组"时,应始终将.extension包含在匹配模式中。映射,因为模式**/*也匹配目录。 为避免这种情况,您可以使用动态映射:

files: {
  expand: true,
  cwd: 'topDir/',
  src: ['**/*', '!**/subdir/**/*', '**/subdir/onlyIncludeThisFromThisDirectory.whatever'],
  dest: 'dest/',
  filter: 'isFile'
}

有关详细信息,请参阅documentation

相关问题