What's a task runner?

A task runner is computer program that runs a sequence of tasks over your source code, applying transformations to the files. For example, consider that you are writing a source code in the CoffeeScript programming language, one task would be compiling all your source code in JavaScript, other task can be concatenating all the output JavaScript files in a single file, and the third task can finally be minifying the concatenated file to minimize the file size.

These tasks will automatically be run by the task runner, you just need to write a script file to program what needs to be done and then forget to run any command line again. The task runner provides triggers to start a task whenever you change a file so that it is done transparently.

As you can see, a task runner can improve your productivity as you can forget about the details of the compilation process once you have correctly configured a task runner. It will allow you to automate all these repetitive and boring tasks and then, you can focus on product development.

Grunt and Gulp are the most popular task runners for JavaScript; they take different approach to run the tasks. In Grunt, the tasks are run sequentially: once a task is running, the next task cannot start until the first is done. In Gulp, the tasks can run parallel to each other, as shown in the following:

What's a task runner?

Figure 7.2 Different approach on running task by Grunt and Gulp

The above figure illustrates how Grunt and Gulp will run three tasks. Task B depends on whether Task A and Task C are done. Note that Grunt can run the tasks parallel to each other using plugins. While, Gulp does this from its core design.

Another difference between Grunt and Gulp is that, in Grunt, you can configure the tasks on writing a big configuration object. While, in Gulp, you will write standard JavaScript functions. An interesting point is that Grunt and Gulp can work together in the same project; however, it is better to choose just one of them in order to reduce complexity.

If your project uses Grunt, you should not switch to Gulp unless have a good reason to do it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.226.255