UNPKG

3.47 kBMarkdownView Raw
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
9Usually you would have to load each task one by one, which is unnecessarily cumbersome.
10
11This 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
16grunt.loadNpmTasks('grunt-shell');
17grunt.loadNpmTasks('grunt-sass');
18grunt.loadNpmTasks('grunt-recess');
19grunt.loadNpmTasks('grunt-sizediff');
20grunt.loadNpmTasks('grunt-svgmin');
21grunt.loadNpmTasks('grunt-styl');
22grunt.loadNpmTasks('grunt-php');
23grunt.loadNpmTasks('grunt-eslint');
24grunt.loadNpmTasks('grunt-concurrent');
25grunt.loadNpmTasks('grunt-bower-requirejs');
26```
27
28#### After
29
30```js
31require('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
46module.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
61require('load-grunt-tasks')(grunt);
62```
63
64Equivalent to:
65
66```js
67require('load-grunt-tasks')(grunt, {pattern: ['grunt-*', '@*/grunt-*']});
68```
69
70### Load all grunt-contrib tasks
71
72```js
73require('load-grunt-tasks')(grunt, {pattern: 'grunt-contrib-*'});
74```
75
76### Load all grunt-contrib tasks and another non-contrib task
77
78```js
79require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', 'grunt-shell']});
80```
81
82### Load all grunt-contrib tasks excluding one
83
84You can exclude tasks using the negate `!` globbing pattern:
85
86```js
87require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', '!grunt-contrib-coffee']});
88```
89
90### Set custom path to package.json
91
92```js
93require('load-grunt-tasks')(grunt, {config: '../package'});
94```
95
96### Only load from `devDependencies`
97
98```js
99require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});
100```
101
102### Only load from `devDependencies` and `dependencies`
103
104```js
105require('load-grunt-tasks')(grunt, {scope: ['devDependencies', 'dependencies']});
106```
107
108### All options in use
109
110```js
111require('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
124Type: `string`, `array`<br>
125Default: `['grunt-*', '@*/grunt-*']` ([globbing pattern](https://github.com/isaacs/minimatch))
126
127### config
128
129Type: `string`, `object`<br>
130Default: Path to nearest package.json
131
132### scope
133
134Type: `string`, `array`<br>
135Default: `['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']`<br>
136Values: `'dependencies'`, `'devDependencies'`, `'peerDependencies'`, `'optionalDependencies'`, `'bundledDependencies'`
137
138### requireResolution
139
140Type: `boolean`<br>
141Default: `false`
142
143Traverse 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
148MIT © [Sindre Sorhus](https://sindresorhus.com)