Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

grunt-contrib-copy: Multiple Copy Tasks

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

like image 709
Keith DC Avatar asked Apr 27 '15 05:04

Keith DC


1 Answers

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

like image 138
jperezov Avatar answered Nov 09 '22 15:11

jperezov