lazy-grunt-loading
Experimental utility to load grunt tasks lazily
The grunt workflow is to load all tasks for every invocation of grunt
, then only run the ones the user actually wants. If you have a project with a ton of grunt tasks, or grunt tasks that take a long time to load, this could end up being painful. To address this pain, I've created a module that makes a few (potentially brittle) assumptions and hooks into grunt.task.run
to only run the tasks you need.
Old way:
Gruntfile.js
module { // Both foo and bar will be loaded every time, even if you are not using all of them. grunt; grunt; grunt foo: fooOpts bar: barOpts };
New way:
Gruntfile.js
module { var lazyGruntLoading = ; // A list of all files that could contain tasks you want to load. // Getting this list is outside the scope of this module. // This list should be fully resolved. // Ex: ['/path/to/node_modules/foo/tasks/grunt-foo.js', '/path/to/tasks/file_name.js'] var taskFiles = // Optional: Not every grunt task is declared in a file of the same name. // Pass an override here to get around this. This is not necessary if // the only difference is the file having the 'grunt-' prefix - that // will get handled automatically. In this example, we see above that // taskFiles has 'tasks/file_name.js', which defines the 'bar' task, // so we add that override here. overrides = file_name: 'bar' // Optional: function to use for logging log = gruntverbosewrite; // Only the tasks you need will be loaded. ; // Config proceeds as it normally would. grunt foo: fooOpts bar: barOpts };
This could ultimately be a bad idea, but I'd like to experiment with it. Because parts of this are brittle, and getting the list of all files a task could be declared in is a burden, I don't recommend using this module unless your task load time is getting painful.
Caveats
- Does not handle
grunt.task.renameTask
- Uses
require('task-module')(grunt)
to load tasks instead ofgrunt.task.load