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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.