So far we’ve looked at simple tasks, but sometimes it’s handy to be able to define a single task that does many things at once. For example, let’s say you were creating next week’s new JavaScript framework and you wanted to create a full version and a micro version that includes only the basics. Using Grunt’s multitasks, you can create a single task definition that iterates over a collection of targets and executes code against those targets with ease.
So what’s a target? You could think of a target as a configuration group for a task. You set up a configuration block that specifies the target and the associated data:
| concat: { |
| basic: { |
| src: ['src/awsome.js'], |
| dest: 'dist/awesome.js', |
| }, |
| full: { |
| src: ['src/awesome.js', 'src/plugins/editor', 'src/plugins/hl.js'], |
| dest: 'dist/awesome-full.js', |
| }, |
| }, |
The task then executes its code against all the targets you specify, using the data to determine what the task should do. Many Grunt plug-ins are implemented as multitasks.
In this chapter, we’ll explore how multitasks work by working first with targets and data, and then with files.
18.222.3.153