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

Pad*_*ddy 1 gruntjs

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

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

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

谢谢,
帕迪

nsc*_*nni 6

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

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

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


Kyl*_*ung 5

预设!遗嘱否定了一种模式:

{expand: true, src: ['dist/**', '!xyz/**']}
Run Code Online (Sandbox Code Playgroud)

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