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