loadTasks as they are needed to speed up Grunt load time
- Dominant language
- JavaScript
- Stars
- 12.2k
- Forks
- 1.5k
- PR merge metrics
- No merged PRs in 30d
Description
The problem is that Grunt loads **all** tasks every time it runs. Even if the user just wants to run `grunt jshint`, it will still load `grunt-uglify`, `grunt-sass`, etc.
This can be slow if a task has a lot of dependencies that are `require`'ed before the task is run.
For example, this is a _slow to load_ task:
``` js
module.exports = function(grunt) {
// These `require` statements execute even if this task isn't run.
var path = require('path'),
semver = require('semver'),
q = require('q'),
utils = require('./utils/utils'),
constants = require('./utils/constants'),
local = require('./core/local')(grunt),
styles = require('./core/styles')(grunt),
debug = require('./utils/debug')(grunt),
install = require('./core/install')(grunt);
grunt.registerTask(
'build',
'Build project',
function(){
// Code here runs when the task runs.
// Grunt would load faster if devs put their `require`
// statements here because they would only run
// when the task is run but it's much more common
// in the Node world to put all `require`s at the top.
// (code removed for this example)
}
);
```
I've made some changes to [time-grunt](https://github.com/sindresorhus/time-grunt) so you can see how long it takes for tasks to load vs their actual run time.

In that screenshot there are other tasks _loading_ that aren't used but they still contribute to the load time.
Contributor guide
Assessment
This issue has not been assessed yet.