How to skip a Grunt target by default

759 views Asked by At

I'm defining a Grunt project with multiple tasks and targets, with task build, I would like to run some copy targets, and then with task deployment, I also want to run copy however with some other targets (only copy folder to specific directory for deployment for example), and I don't want to execute this target at build task.

So how can I skip this Grunt target from the build

Here is my example

grunt.registerTask('build', ['clean', 'copy']);
grunt.registerTask('deployment', ['copy:deployment']);

grunt.initConfig(
  {
    copy: {
      foo: // Do something here,
      bar: // Do anothering here,
      ....
      deployment: // Copy file and execute something for deployment target.
    },
  }
);
2

There are 2 answers

1
Juank On
grunt.registerTask('build', ['clean', 'copy:foo', 'copy:bar']);
grunt.registerTask('deployment', ['copy:deployment']);
2
rgruenke On

I would suggest you specify the copy targets for your build task like copy:build for a generic target or like copy:foo, copy:bar.. I don't think it's possible to opt out for a single not wanted target in grunt (unless you create a generic task by a function call)

EDIT:

//something like this
grunt.registerTask('copy:build', function(){
  var copyConfig = grunt.config.get('copy');
  Object.keys(copyConfig).forEach(function(target){
    if(target !== 'deployment'){
      grunt.task.run('copy:'+target)
    }

  });
})

grunt.registerTask('build', ['clean', 'copy:build']);
//etc