Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

gruntjs

yeoman

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');
like image 622
acme Avatar asked Dec 14 '12 12:12

acme


People also ask

Can we configure Grunt to run one or more tasks by default by defining a default task?

Tasks are grunt's bread and butter. The stuff you do most often, like jshint or nodeunit . Every time Grunt is run, you specify one or more tasks to run, which tells Grunt what you'd like it to do. If you don't specify a task, but a task named "default" has been defined, that task will run (unsurprisingly) by default.

Is Grunt a task runner?

Grunt is a JavaScript task runner, a tool used to automatically perform frequent tasks such as minification, compilation, unit testing, and linting. It uses a command-line interface to run custom tasks defined in a file (known as a Gruntfile). Grunt was created by Ben Alman and is written in Node. js.

How do you check if a task exists in Grunt?

grunt.task.existsCheck with the name, if a task exists in the registered tasks.

Which Grunt plugin is used to run predefined tasks when the watched file changes?

grunt-este-watchby Daniel SteigerwaldRun predefined tasks whenever watched file changes.


1 Answers

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
// ...
like image 149
Dmitry Pashkevich Avatar answered Oct 08 '22 10:10

Dmitry Pashkevich