grunt-contrib-copy: Multiple Copy Tasks
Asked Answered
F

2

11

Was just wondering if it's possible to set the 'copy' task to do selective copies? Say, if one task wanted to target some files for copying, while another task may want to target others.

I see the 'main' is used in all the examples, but I can't find reference to if other names are able to be used, or another way to accomplish this, outside of using grunt-multi-dest

    copy: {
      main: {
        files: [
          {
            cwd: 'src_static/img/',
            src: ['**'],
            dest: '../mainProject/assets/img/'
          }
        ],
      onlyIcons: {
        files: [
          {
            cwd: 'src_static/img/icons/',
            src: ['**'],
            dest: '../mainProject/assets/img/icons/'
          }
        ],
      }
    }
    grunt.registerTask('copy-all', ['copy']);
    grunt.registerTask('copy-icons', ['copy:onlyIcons']);

Although closed, I was asked to reference the question I posted as an issue on the grunt-contrib-copy site: https://github.com/gruntjs/grunt-contrib-copy/issues/230#issuecomment-96467261

Thanks. -Keith

Fecula answered 27/4, 2015 at 5:22 Comment(0)
F
0

Looks like grunt-multi-dest appears to be the clear winner. Even then, there's not much downside to just including and using it. It fills the gap nicely.

Fecula answered 22/5, 2015 at 22:59 Comment(0)
S
15

For anyone coming across this now, this actually works:

grunt.registerTask('copy-all', ['copy']);
grunt.registerTask('copy-icons', ['copy:onlyIcons']);

This is going off of KDCinfo's initial Gruntfile config:

copy: {
    main: {
        files: [{
            cwd: 'src_static/img/',
            src: ['**'],
            dest: '../mainProject/assets/img/'
        }]
    },
    onlyIcons: {
        files: [{
            cwd: 'src_static/img/icons/',
            src: ['**'],
            dest: '../mainProject/assets/img/icons/'
        }],
    }
}

and shows that the copy.main and copy.onlyIcons must be called as copy:main and copy:onlyIcons within grunt.registerTask().

Sigma answered 19/2, 2016 at 19:19 Comment(1)
That was hard to find. This should also be the accepted answer, because it works not only with that particular plugin.Sikkim
F
0

Looks like grunt-multi-dest appears to be the clear winner. Even then, there's not much downside to just including and using it. It fills the gap nicely.

Fecula answered 22/5, 2015 at 22:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.