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`/`optionalDependencies` in your package.json and load grunt tasks that match the provided patterns.
|
8 |
|
9 | #### Before
|
10 |
|
11 | ```js
|
12 | grunt.loadNpmTasks('grunt-shell');
|
13 | grunt.loadNpmTasks('grunt-sass');
|
14 | grunt.loadNpmTasks('grunt-recess');
|
15 | grunt.loadNpmTasks('grunt-sizediff');
|
16 | grunt.loadNpmTasks('grunt-svgmin');
|
17 | grunt.loadNpmTasks('grunt-styl');
|
18 | grunt.loadNpmTasks('grunt-php');
|
19 | grunt.loadNpmTasks('grunt-eslint');
|
20 | grunt.loadNpmTasks('grunt-concurrent');
|
21 | grunt.loadNpmTasks('grunt-bower-requirejs');
|
22 | ```
|
23 |
|
24 | #### After
|
25 |
|
26 | ```js
|
27 | require('load-grunt-tasks')(grunt);
|
28 | ```
|
29 |
|
30 |
|
31 | ## Install
|
32 |
|
33 | ```
|
34 | $ npm install --save-dev load-grunt-tasks
|
35 | ```
|
36 |
|
37 |
|
38 | ## Usage
|
39 |
|
40 | ```js
|
41 | // Gruntfile.js
|
42 | module.exports = grunt => {
|
43 | // Load all grunt tasks matching the ['grunt-*', '@*/grunt-*'] patterns
|
44 | require('load-grunt-tasks')(grunt);
|
45 |
|
46 | grunt.initConfig({});
|
47 | grunt.registerTask('default', []);
|
48 | };
|
49 | ```
|
50 |
|
51 |
|
52 | ## Examples
|
53 |
|
54 | ### Load all grunt tasks
|
55 |
|
56 | ```js
|
57 | require('load-grunt-tasks')(grunt);
|
58 | ```
|
59 |
|
60 | Equivalent to:
|
61 |
|
62 | ```js
|
63 | require('load-grunt-tasks')(grunt, {pattern: ['grunt-*', '@*/grunt-*']});
|
64 | ```
|
65 |
|
66 | ### Load all grunt-contrib tasks
|
67 |
|
68 | ```js
|
69 | require('load-grunt-tasks')(grunt, {pattern: 'grunt-contrib-*'});
|
70 | ```
|
71 |
|
72 | ### Load all grunt-contrib tasks and another non-contrib task
|
73 |
|
74 | ```js
|
75 | require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', 'grunt-shell']});
|
76 | ```
|
77 |
|
78 | ### Load all grunt-contrib tasks excluding one
|
79 |
|
80 | You can exclude tasks using the negate `!` globbing pattern:
|
81 |
|
82 | ```js
|
83 | require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', '!grunt-contrib-coffee']});
|
84 | ```
|
85 |
|
86 | ### Set custom path to package.json
|
87 |
|
88 | ```js
|
89 | require('load-grunt-tasks')(grunt, {config: '../package'});
|
90 | ```
|
91 |
|
92 | ### Only load from `devDependencies`
|
93 |
|
94 | ```js
|
95 | require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});
|
96 | ```
|
97 |
|
98 | ### Only load from `devDependencies` and `dependencies`
|
99 |
|
100 | ```js
|
101 | require('load-grunt-tasks')(grunt, {scope: ['devDependencies', 'dependencies']});
|
102 | ```
|
103 |
|
104 | ### All options in use
|
105 |
|
106 | ```js
|
107 | require('load-grunt-tasks')(grunt, {
|
108 | pattern: 'grunt-contrib-*',
|
109 | config: '../package.json',
|
110 | scope: 'devDependencies',
|
111 | requireResolution: true
|
112 | });
|
113 | ```
|
114 |
|
115 |
|
116 | ## Options
|
117 |
|
118 | ### pattern
|
119 |
|
120 | Type: `string | string[]`<br>
|
121 | Default: `['grunt-*', '@*/grunt-*']` ([Glob pattern](https://github.com/isaacs/minimatch))
|
122 |
|
123 | ### config
|
124 |
|
125 | Type: `string | object`<br>
|
126 | Default: Path to nearest package.json
|
127 |
|
128 | ### scope
|
129 |
|
130 | Type: `string | string[]`<br>
|
131 | Default: `['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']`<br>
|
132 | Values: `'dependencies'`, `'devDependencies'`, `'peerDependencies'`, `'optionalDependencies'`, `'bundledDependencies'`
|
133 |
|
134 | ### requireResolution
|
135 |
|
136 | Type: `boolean`<br>
|
137 | Default: `false`
|
138 |
|
139 | 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.
|