如何在使用grunt-contrib-compress进行压缩时排除文件夹根目录并仅包含内容

时间:2013-07-26 09:32:12

标签: gruntjs

在压缩文件夹中的所有文件时,有没有办法可以排除文件夹根目录?

grunt.initConfig({
  compress: {
    main: {
      files: [
        {expand: true, src: ['dist/**', 'xyz/**']},
      ]
    }
  }   
});

我们如何排除dist和xyz文件夹不包含在压缩文件中?

谢谢,
稻谷

2 个答案:

答案 0 :(得分:6)

如果您想要包含该文件夹下的文件,则需要更改每个目标的cwd,以便将它们视为每个glob模式的根

grunt.initConfig({
  compress: {
    main: {
      files: [
        {cwd: 'dist/', expand: true, src: ['**']},
        {cwd: 'xyz/', expand: true, src: ['**']},
      ]
    }
  }   
});

如果您只想排除根目录中的文件夹,请使用Kyle提到的!模式

答案 1 :(得分:5)

预先设置!将取消模式:

{expand: true, src: ['dist/**', '!xyz/**']}

请参阅:http://gruntjs.com/configuring-tasks#globbing-patterns

相关问题