Skip to content

yleo77/grunt-task-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grunt-task-loader

Build Status NPM version

Speed up task loading and load npm grunt tasks automatically

Before:

// gruntfile.js
module.exports = function(grunt) {

  // configure tasks

  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-watch');
  grunt.loadNpmTasks('grunt-...');
  grunt.loadTasks('foo');
  grunt.loadTasks('bar');
  grunt.loadTasks('...');
}

After:

// gruntfile.js
module.exports = function(grunt) {

  require('grunt-task-loader')(grunt);

  // configure tasks
}

Sample time output before:

// output by time-grunt
Execution Time (2014-10-14 07:32:26 UTC)
loading tasks  6.7s  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 98%
reset           130ms  ▇▇ 2%
Total 6.83s

Sample time output after:

Execution Time (2014-10-14 07:33:32 UTC)
loading tasks  156ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 52%
loading reset   14ms  ▇▇▇ 5%
reset           130ms  ▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 43%
Total 318ms

Install

npm install grunt-task-loader --save-dev

Usage

Simple:

// Must go at the top of your gruntfile, before the task config.
require('grunt-task-loader')(grunt);

With Options:

require('grunt-task-loader')(grunt, {
  customTasksDir: '__CUSTOM_DIR__',   // or ['__CUSTOM_DIR__'],
  mapping: {
    taskA: 'another_tasks_dirs/', // custom task 'taskA' from custom tasks directory (load by grunt.loadTasks API)
    taskB: 'ultraman/frog.js',    // custom task from file
    cachebreaker: 'grunt-cache-breaker' // taskname mapping to package-name. will look in node_modules.
  }
});

Options

customTasksDir

  • Type: string,array
  • Default: []

mapping

  • Type: object
  • Default: {}

Key is the grunt task name (as referenced in grunt config for that task), and value is the name of that task's package as it can be found in the filesystem.

mappingExample:
require('grunt-task-loader')(grunt, {
  mapping: {
    express: 'grunt-express-server'
  }
});

convertCamelCase

  • Type: boolean
  • Default: true

Automatically handles grunt tasks whose task names have been defined in camelCase while their package names are in param-case (this could also be handled per-task in custom mappings). Examples: ngAnnotate, includeSource, etc.



See Gruntfile.js for more live examples.



Help: task not found

grunt-task-loader optimizes task loading by only loading the tasks needed for the current task list, instead of loading all of the 'grunt-' prefixed tasks in the package.json. To do this, it reads the task names from the grunt config. Sometimes, grunt task authors give the grunt task a name that doesn't correspond to the npm package they publish the plugin under. Example: grunt-express-server is configured with:

grunt.initConfig({
  express: { // not express-server
    // options
  }
});

So in this case, pass the name mapping in the options argument to grunt-task-loader:

require('grunt-task-loader')(grunt, {
  mapping: {
    express: 'grunt-express-server'
  }
});

You can also submit a PR to add this name mapping to the plugin defaults.

Package names that are simply prefixed with 'grunt-' or 'grunt-contrib-' are automatically handled, and so are mappings like ngAnnotate to grunt-ng-annotate, if convertCamelCase is true.

License

MIT

About

A grunt task loader for Grunt.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published