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)

Gruntfile.js wrapper and configuration


Gruntfile.js implements the module pattern that injects the grunt object into its callback function. It is described as a wrapper as it effectively wraps all of the code that will make up the module. Additionally, Gruntfile.js includes all of the configuration for each plugin that is going to be included within. The following sections describe the wrapper and configuration sections of Gruntfile.js.

Wrapper

The wrapper function contains all of the Grunt-related code within its body. Recall the example from Chapter 4, Configuration of Grunt Tasks:

module.exports = function(grunt) {
  // grunt related code
};

The module.exports function encapsulates the code within to create an object with properties; in this case, we refer to it as a module. The module.exports function is set equal to a function that takes the Grunt object as its argument. Without the module.exports function or the anonymous function, which takes the grunt object as a parameter, none of the...