Book Image

Learning Grunt

By : Douglas Reynolds
Book Image

Learning Grunt

By: Douglas Reynolds

Overview of this book

With the increasing focus on task automation, the Grunt task runner is a vast platform that allows you to incorporate automation into your workflows. At the outset, you will learn how to use Node.js and NMP through an example. You will then find out how to build a sample app and the development environment for it. You will further delve into the implementation of Grunt plugins and the configuration of Grunt tasks. Furthermore, you will explore the various methods and packages for workflow automation. The final chapter will cover some advanced concepts, such as configuration variables and how to create a Grunt plugin. By the end of the book, you will have gained the fundamentals of Grunt and progressed through advanced concepts, including building a Grunt plugin.
Table of Contents (15 chapters)

The default task configuration


Creating the default task is as simple as loading tasks. Grunt has a registerTask method that we use to name (alias) the task and provide a list of one or more tasks to be run. When the task alias is run, all of the associated tasks in its list are run. In this way we can create a single command that runs the task(s) in the associated list. Additionally, the order of the tasks in the list defines the order in which the tasks are run; this provides us with even more refined control.

The basic task configuration syntax is:

grunt.registerTask(task_name, task_list);

In order to define the default task, the task name given should be 'default'. This task will run all of the associated tasks in its list even if no tasks are specified. For example, in order to run the default task, all that is needed is to issue the grunt command in the command prompt. The list argument to the registerTask method is an array of tasks. This syntax looks like the following example:

grunt...