Paddy
Paddy

Reputation: 3630

How to exclude a folder root and include only contents while zipping using grunt-contrib-compress

Is there a way by which we can exclude the folder root when you are compressing all files within a folder?

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

How can we exclude dist and xyz folders from being included in the compressed file?

Thanks,
Paddy

Upvotes: 1

Views: 3726

Answers (2)

nschonni
nschonni

Reputation: 4129

If your want the files under the folder included, you need to change the cwd for each target so that they are treated as the root for each glob pattern

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

If you are looking just exclude the folders in the root, then use ! patterns that Kyle mentioned

Upvotes: 6

Kyle Robinson Young
Kyle Robinson Young

Reputation: 13762

Prepending a ! will negate a pattern:

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

See: http://gruntjs.com/configuring-tasks#globbing-patterns

Upvotes: 6

Related Questions