Enter Your Email Address to Watch This Lesson

Your link to unlock this lesson will be sent to this email address.

Unlock this lesson and all 832 of the free egghead.io lessons, plus get JavaScript content delivered directly to your inbox!



Existing egghead members will not see this. Sign in.

Just one more step!

Check your inbox for an email from us and click link to unlock your lesson.



Multitask

1:49 JavaScript lesson by

Grunt Multitask allows you to write complex tasks that run multiple targets. In this lesson, John will show you how to use Multitask in your GruntJS builds.


egghead.io comment guidelines

Avatar
egghead.io

Grunt Multitask allows you to write complex tasks that run multiple targets. In this lesson, John will show you how to use Multitask in your GruntJS builds.

John Lindquist: Registering multitasks allows you to either iterate through or choose just an individual task to run from a list.

I say, "grunt.registerMultiTask." Say "tasks" is the name of it. Then, in here, I will "grunt.log.writeln(this.target)."

That'll just be the name of the task. We configure something called "tasks" here, and we just have "one" and nothing.

Then we come down to the terminal, and we run grunt tasks. You can see that it logs out "one," because that is the name of that first task.

If we add "two" to this, I can run grunt tasks. You can see it runs "one," then "two."

I can also just run grunt tasks and target "one," and that'll only run "one," or "grunt tasks:two," and that will only run "two."

You can basically get the target and the data. We can say "target" plus some empty space plus "this.data."

In here, we want the data to be "first" and the data to be "second." Then we'll just add a third one for good measure, or "three" and "third."

If I go "grunt tasks," you can see it runs "one" first, "two" second, "three" third. Then I can run any of them that I want. "Tasks:three," and it'll run "three" third.

Basically, you're taking this task you wrote. You can pass in any of the data, "one, two, three," into your task, use the target and data to run this however you want.

HEY, QUICK QUESTION!
Joel's Head
Why are we asking?