This Lesson is for Members

Subscribe today and get access to all lessons! Plus direct HD download for offline use, enhances transcripts, member comment forums, and iTunes "podcast" RSS feed. Level up your skills now!

Unlock This Lesson

Already subscribed? Sign In

Autoplay

    Multitask

    John LindquistJohn Lindquist

    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.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    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.

    Discuss

    Discuss