-
Book Overview & Buying
-
Table Of Contents
Getting Started with Grunt: The JavaScript Task Runner
By :
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 example 03-load-plugin
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadTasks("./node_modules/grunt-contrib-copy/tasks");Now, with this in mind, if we want to create and share our own tasks, we can publish them as a plugin. All we need to do is:
Write...
Change the font size
Change margin width
Change background colour