Load multiple grunt tasks using globbing patterns
npm install load-grunt-tasks> Load multiple grunt tasks using globbing patterns
Usually you would have to load each task one by one, which is unnecessarily cumbersome.
This module will read the dependencies/devDependencies/peerDependencies/optionalDependencies in your package.json and load grunt tasks that match the provided patterns.
#### Before
``js`
grunt.loadNpmTasks('grunt-shell');
grunt.loadNpmTasks('grunt-sass');
grunt.loadNpmTasks('grunt-recess');
grunt.loadNpmTasks('grunt-sizediff');
grunt.loadNpmTasks('grunt-svgmin');
grunt.loadNpmTasks('grunt-styl');
grunt.loadNpmTasks('grunt-php');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-concurrent');
grunt.loadNpmTasks('grunt-bower-requirejs');
#### After
`js`
require('load-grunt-tasks')(grunt);
``
$ npm install --save-dev load-grunt-tasks
`js
// Gruntfile.js
module.exports = grunt => {
// Load all grunt tasks matching the ['grunt-', '@/grunt-*'] patterns
require('load-grunt-tasks')(grunt);
grunt.initConfig({});
grunt.registerTask('default', []);
};
`
`js`
require('load-grunt-tasks')(grunt);
Equivalent to:
`js`
require('load-grunt-tasks')(grunt, {pattern: ['grunt-', '@/grunt-*']});
`js`
require('load-grunt-tasks')(grunt, {pattern: 'grunt-contrib-*'});
`js`
require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', 'grunt-shell']});
You can exclude tasks using the negate ! globbing pattern:
`js`
require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', '!grunt-contrib-coffee']});
`js`
require('load-grunt-tasks')(grunt, {config: '../package'});
`js`
require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});
`js`
require('load-grunt-tasks')(grunt, {scope: ['devDependencies', 'dependencies']});
`js`
require('load-grunt-tasks')(grunt, {
pattern: 'grunt-contrib-*',
config: '../package.json',
scope: 'devDependencies',
requireResolution: true
});
Type: string | string[]['grunt-', '@/grunt-*']
Default: (Glob pattern)
Type: string | object
Default: Path to nearest package.json
Type: string | string[]['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']
Default: 'dependencies'
Values: , 'devDependencies', 'peerDependencies', 'optionalDependencies', 'bundledDependencies'
Type: booleanfalse
Default:
Traverse up the file hierarchy looking for dependencies like require(), rather than the default grunt-like behavior of loading tasks only in the immediate node_modules` directory.