Grunt plugins

With the concepts from the section above, it becomes easy to understand how Grunt plugins work. Grunt plugins are just normal Node.js modules (that is, any directory with a package.json file), with the addition that they contain a tasks directory with JavaScript files to load. As we have seen throughout this book, when we wish to load the tasks provided by a Grunt plugin, we call the grunt.loadNpmTasks function with the name of the module. This loadNpmTasks function is very similar to the loadTasks function described previously, however, instead of using a directory to find JavaScript files, it uses the name of a module and then looks inside that module for a tasks folder. Therefore, the following two lines are equivalent:

//Code ...

Get Getting Started with Grunt: The JavaScript Task Runner now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.