Book Image

Grunt Cookbook

By : Jurie-Jan Botha
Book Image

Grunt Cookbook

By: Jurie-Jan Botha

Overview of this book

<p>A web application can quickly turn into a complex orchestration of many smaller components, each one requiring its own bit of maintenance. Grunt allows you to automate all the repetitive tasks required to get everything working together by using JavaScript, the most popular programming language.</p> <p>Grunt Cookbook offers a host of easy-to-follow recipes for automating repetitive tasks in your web application's development, management, and deployment processes. This book will introduce you to methods that can be used to automate basic processes and your favorite tools. By following the recipes, you will soon be comfortable using Grunt to perform a wide array of advanced tasks in a range of different scenarios.</p>
Table of Contents (17 chapters)
Grunt Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Installing the Grunt CLI


In order to make use of a Grunt configuration file, the Grunt command-line interface (CLI) tool needs to be installed.

Command-line tools such as the Grunt CLI are usually installed globally. This means that they are installed on top of the Node.js installation that is currently active in your terminal, and not in the current project path, as is usually the case.

Tip

In this book, we'll work with version 0.4.x of Grunt, which requires Node.js version 0.8.x or higher.

How to do it...

The following steps will take us through installing the Grunt CLI and testing for its successful installation.

  1. Assuming that you already have a global installation of Node.js, the following is the command to install the Grunt CLI:

    $ npm install --global grunt-cli
    
  2. If the installation was successful, the grunt command should now be available on the terminal. Test this by typing grunt in your terminal and confirm that it returns a message similar to the following:

    grunt-cli: The grunt command line interface. (v0.1.13)
    
    Fatal error: Unable to find local grunt.
    
    If you're seeing this message, either a Gruntfile wasn't found or grunt hasn't been installed locally to your project. For more information about installing and configuring grunt, please see the Getting Started guide:
    
    http://gruntjs.com/getting-started
    

How it works...

The npm install command looks up the grunt-cli package on npm's public package registry, and proceeds to download and install it once it is found.

Using the -g argument along with the install command indicates that the package we'd like to install, should be installed globally, meaning it should be installed on the version of Node.js that is currently active in our terminal.

In a default Node.js setup, a folder for executable binaries will automatically be added as a path that should be scanned by the terminal for executable commands. This makes the grunt command automatically available after the installation of this package, as its executable binary is provided and indicated in the package's installation information.