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

Keith DC
  • 661
  • 1
  • 9
  • 24

2 Answers2

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().

Kelderic
  • 6,502
  • 8
  • 46
  • 85
jperezov
  • 3,041
  • 1
  • 20
  • 36
  • That was hard to find. This should also be the accepted answer, because it works not only with that particular plugin. – Fusseldieb Aug 21 '18 at 17:56
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.

Keith DC
  • 661
  • 1
  • 9
  • 24