How can I load two grunt tasks with the same name?

2020-03-01 07:42发布

Im using yeoman for a project.

Basically it's working fine, but during the build process I want to move my images folder to somewhere else.

So I loaded the grunt-contrib-copy task which would let me do that. But unfortunately this conflicts with the yeoman built-in copy task.

Is there any way to alias the grunt-contrib-copy in my Gruntfile.js so I can use both of them?

grunt.loadNpmTasks('grunt-contrib-copy');

//Here I need to use "copy" again but not referencing the yeoman task but the grunt-contrib-copy task.
grunt.registerTask('build','intro clean coffee compass mkdirs concat css min replace copy time');

1条回答
成全新的幸福
2楼-- · 2020-03-01 08:13

grunt.renameTask() will probably help you here. Try this:

// temporarily rename yeoman's copy task
grunt.renameTask('copy', 'yeomanCopy');
// load 'copy' from grunt-contrib-copy
grunt.loadNpmTasks('grunt-contrib-copy');
// rename it to something other than 'copy'
grunt.renameTask('copy', 'myCopy');
// rename yeoman's task back to its original name so nothing breaks
grunt.renameTask('yeomanCopy', 'copy');

// now use 'myCopy' for your purposes
// ...
查看更多
登录 后发表回答