Book Image

Mastering Grunt

By : Daniel Li
Book Image

Mastering Grunt

By: Daniel Li

Overview of this book

<p>Grunt.js continues to excel as the build automation tool of choice. Along with its support for many third-party technologies, Grunt is packaged with a clean API for defining tasks. This powerful tool can streamline your workflow by automating the preparation tasks for production, such as compression, compilation, obfuscation, testing, and even pushing your web application live. This book will teach you how to master build automation and testing with Grunt. You will have the opportunity to utilize the latest and in-demand web tools, such as Git, Jade, CoffeeScript, Sass, and the Mocha testing engine, across several exciting projects by combining Grunt with them. You will also learn to create a project – a simple Bulletin Board System (BBS), which will explain the use of Grunt alongside the Mocha testing library to automate testing throughout the build process.</p> <p>Mastering Grunt will demonstrate how to leverage Grunt with other technologies to become an expert in build automation, teaching you the best practices for modern web development along the way.</p>
Table of Contents (12 chapters)

Installing Grunt


In this section, the installation of Grunt and any potential setup issues will be addressed.

Installation steps

There are no use cases for which Grunt should be installed globally. The configuration of Grunt and its associated plugins will be provided in each of the projects within this book.

When starting a new project, you can install Grunt within the project directory by issuing the following command:

npm install grunt

Any Grunt plugins that will be used in the projects of this book will also be installed through npm. The installation steps for each plugin will be included in each project.

Troubleshooting

In this section, various troubleshooting errors will be explored and diagnosed.

Grunt: command not found

This error is typically caused by the lack of grunt-cli, the command-line interface for Grunt. As per the best practices suggested by the Node community itself, Grunt is intended to be installed locally for each project. Any command-line tools such as grunt-cli are intended to be installed globally. Thus, you should issue a global installation of grunt-cli in order to fix this problem, as shown in the following command:

npm install -g grunt-cli

Fatal error: Unable to find local grunt

When you receive this error, it is because a local Grunt binary cannot be found within the Node modules of the project. This typically occurs when grunt-cli is installed but Grunt is uninstalled or missing.

To fix this problem, just reinstall Grunt locally, ensuring that it is added to your package.json file by passing the --save-dev flag, as shown in the following command:

npm install --save-dev grunt