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)

Understanding task loading


The process and syntax for loading a task are quite simple and very straightforward. In fact, the basic way to load a task is a simple one-liner using Grunt's loadNpmTasks method.

The syntax is:

grunt.loadNpmTasks('name-of-task');

The name-of-task, as shown in the example, would be the name of the task as defined in sample_project's package.json devDependencies object. So, for instance, to load grunt-contrib-uglify we would specify it as the argument in the loadNpmTasks method like this:

grunt.loadNpmTasks('grunt-contrib-uglify');

Using the LoadNpmTasks method

A little about loadNpmTasks. The loadNpmTasks method is a method that loads plugins installed locally with NPM (it will not load tasks installed via other means) and that have been installed relative to the gruntfile. In order to load tasks not installed with NPM, one would use grunt.loadTasks, an alias for grunt.task.loadTasks. Additionally, for tasks that have been installed with NPM, one may also use grunt...