Reputation: 14216
I have a grunt file I am trying to see if I can split so I can call something like grunt build:dev
or grunt build:prod
.
Right now the task looks like this -
grunt.registerTask('build', "Building all needed files.", [
'clean:build',
'check-code',
'clean:dist',
'dist:prepare',
'copy',
'cssmin',
'injector',
'webpack:prod',
'create-status-page'
]);
And I am wondering if there is a way to split this task like you can with configs with a key of dev
and prod
, where the task list for prod it slight different than dev. Sort of similiar to how you might do it with tha configs like
return {
dev: {
...
},
prod: {
...
}
}
Is something like this possible? To be clear, I am asking if I can get away with registering both these in a single task.
Upvotes: 1
Views: 150
Reputation: 1926
You may be able to use a multitask.
grunt.initConfig({
build: {
dev: ['task1', 'task2', 'task3'],
prod: ['taskA', 'taskB', 'taskC']
}
});
grunt.registerMultiTask('build', 'Building...', function() {
grunt.task.run(this.data);
});
Then you can do grunt build:dev
or grunt build:prod
Note: If you just do grunt build
, it will iterate through all of the properties, so it would run both dev tasks and prod tasks.
Upvotes: 3