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)

Introducing the Grunt API


Uptil now, we haven't discussed any details of the Grunt Application Programming Interface (API). If the appearance of grunt in or around all of the gruntfile code snippets that we have seen so far has caught your eye, then you are to be congratulated for noticing that grunt is providing some things that we need in order to set up and configure our automated tasks.

Grunt exposes all of its properties and methods via the grunt object. Returning to the wrapper function that was provided as an example in the beginning of the gruntfile.js section, we can see that its anonymous function takes the grunt object as its only argument:

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

It is through the grunt object that we can access all of its properties and methods and this is why this wrapper method is required.

A discussion of modules will be useful in order to get a better understanding of how node.js can share items, such as objects, properties, and methods...