Load All Grunt Plugins With One Line Of Code

When I first began using Grunt, I loaded my plugins by calling grunt.loadNpmTask() manually. While this is fine when working with a few Grunt plugins, as you install more, it can be a pain to have to add another loading declaration as well as configuring the task.

So when I discovered that you could use matchdep to load all of the Grunt plugins listed in the package.json file with a single line of code, I immediately began to adopt this practice.

require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

However, I have recently discovered that there is a better way. Enter load-grunt-tasks, a node module that is specifically designed for loading multiple Grunt plugins at once.

Now all you need to load all Grunt tasks is:

require('load-grunt-tasks')(grunt);

Of course, there are plenty of configuration options available, if you need them

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.