1 | # load-grunt-tasks [![Build Status](https://travis-ci.org/sindresorhus/load-grunt-tasks.svg?branch=master)](https://travis-ci.org/sindresorhus/load-grunt-tasks)
|
2 |
|
3 | > Load multiple grunt tasks using globbing patterns
|
4 |
|
5 | Usually you would have to load each task one by one, which is unnecessarily cumbersome.
|
6 |
|
7 | This module will read the `dependencies`/`devDependencies`/`peerDependencies` in your package.json and load grunt tasks that match the provided patterns.
|
8 |
|
9 |
|
10 | #### Before
|
11 |
|
12 | ```js
|
13 | grunt.loadNpmTasks('grunt-shell');
|
14 | grunt.loadNpmTasks('grunt-sass');
|
15 | grunt.loadNpmTasks('grunt-recess');
|
16 | grunt.loadNpmTasks('grunt-sizediff');
|
17 | grunt.loadNpmTasks('grunt-svgmin');
|
18 | grunt.loadNpmTasks('grunt-styl');
|
19 | grunt.loadNpmTasks('grunt-php');
|
20 | grunt.loadNpmTasks('grunt-eslint');
|
21 | grunt.loadNpmTasks('grunt-concurrent');
|
22 | grunt.loadNpmTasks('grunt-bower-requirejs');
|
23 | ```
|
24 |
|
25 | #### After
|
26 |
|
27 | ```js
|
28 | require('load-grunt-tasks')(grunt);
|
29 | ```
|
30 |
|
31 |
|
32 | ## Install
|
33 |
|
34 | ```bash
|
35 | $ npm install --save-dev load-grunt-tasks
|
36 | ```
|
37 |
|
38 |
|
39 | ## Example config
|
40 |
|
41 | ```js
|
42 | // Gruntfile.js
|
43 | module.exports = function (grunt) {
|
44 | // load all grunt tasks matching the `grunt-*` pattern
|
45 | require('load-grunt-tasks')(grunt);
|
46 |
|
47 | grunt.initConfig({});
|
48 | grunt.registerTask('default', []);
|
49 | }
|
50 | ```
|
51 |
|
52 |
|
53 | ## Usage examples
|
54 |
|
55 | ### Load all grunt tasks
|
56 |
|
57 | ```js
|
58 | require('load-grunt-tasks')(grunt);
|
59 | ```
|
60 |
|
61 | Equivalent to:
|
62 |
|
63 | ```js
|
64 | require('load-grunt-tasks')(grunt, {pattern: 'grunt-*'});
|
65 | ```
|
66 |
|
67 | ### Load all grunt-contrib tasks
|
68 |
|
69 | ```js
|
70 | require('load-grunt-tasks')(grunt, {pattern: 'grunt-contrib-*'});
|
71 | ```
|
72 |
|
73 | ### Load all grunt-contrib tasks and another non-contrib task
|
74 |
|
75 | ```js
|
76 | require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', 'grunt-shell']});
|
77 | ```
|
78 |
|
79 | ### Load all grunt-contrib tasks excluding one
|
80 |
|
81 | You can exclude tasks using the negate `!` globbing pattern:
|
82 |
|
83 | ```js
|
84 | require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', '!grunt-contrib-coffee']});
|
85 | ```
|
86 |
|
87 | ### Set custom path to package.json
|
88 |
|
89 | ```js
|
90 | require('load-grunt-tasks')(grunt, {config: '../package'});
|
91 | ```
|
92 |
|
93 | ### Only load from `devDependencies`
|
94 |
|
95 | ```js
|
96 | require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});
|
97 | ```
|
98 |
|
99 | ### Only load from `devDependencies` and `dependencies`
|
100 |
|
101 | ```js
|
102 | require('load-grunt-tasks')(grunt, {scope: ['devDependencies', 'dependencies']});
|
103 | ```
|
104 |
|
105 | ### All options in use
|
106 |
|
107 | ```js
|
108 | require('load-grunt-tasks')(grunt, {
|
109 | pattern: 'grunt-contrib-*',
|
110 | config: '../package.json',
|
111 | scope: 'devDependencies'
|
112 | });
|
113 | ```
|
114 |
|
115 |
|
116 | ## Options
|
117 |
|
118 | ### pattern
|
119 |
|
120 | Type: `String`, `Array`
|
121 | Default: `'grunt-*'` ([globbing pattern](https://github.com/isaacs/minimatch))
|
122 |
|
123 | ### config
|
124 |
|
125 | Type: `String`, `Object`
|
126 | Default: Path to nearest package.json
|
127 |
|
128 | ### scope
|
129 |
|
130 | Type: `String`, `Array`
|
131 | Default: `['dependencies', 'devDependencies', 'peerDependencies']`
|
132 |
|
133 |
|
134 | ## License
|
135 |
|
136 | [MIT](http://opensource.org/licenses/MIT) © [Sindre Sorhus](http://sindresorhus.com)
|