UNPKG

2.82 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
5Usually you would have to load each task one by one, which is unnecessarily cumbersome.
6
7This 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
13grunt.loadNpmTasks('grunt-shell');
14grunt.loadNpmTasks('grunt-sass');
15grunt.loadNpmTasks('grunt-recess');
16grunt.loadNpmTasks('grunt-sizediff');
17grunt.loadNpmTasks('grunt-svgmin');
18grunt.loadNpmTasks('grunt-styl');
19grunt.loadNpmTasks('grunt-php');
20grunt.loadNpmTasks('grunt-eslint');
21grunt.loadNpmTasks('grunt-concurrent');
22grunt.loadNpmTasks('grunt-bower-requirejs');
23```
24
25#### After
26
27```js
28require('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
43module.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
58require('load-grunt-tasks')(grunt);
59```
60
61Equivalent to:
62
63```js
64require('load-grunt-tasks')(grunt, {pattern: 'grunt-*'});
65```
66
67### Load all grunt-contrib tasks
68
69```js
70require('load-grunt-tasks')(grunt, {pattern: 'grunt-contrib-*'});
71```
72
73### Load all grunt-contrib tasks and another non-contrib task
74
75```js
76require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', 'grunt-shell']});
77```
78
79### Load all grunt-contrib tasks excluding one
80
81You can exclude tasks using the negate `!` globbing pattern:
82
83```js
84require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', '!grunt-contrib-coffee']});
85```
86
87### Set custom path to package.json
88
89```js
90require('load-grunt-tasks')(grunt, {config: '../package'});
91```
92
93### Only load from `devDependencies`
94
95```js
96require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});
97```
98
99### Only load from `devDependencies` and `dependencies`
100
101```js
102require('load-grunt-tasks')(grunt, {scope: ['devDependencies', 'dependencies']});
103```
104
105### All options in use
106
107```js
108require('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
120Type: `String`, `Array`
121Default: `'grunt-*'` ([globbing pattern](https://github.com/isaacs/minimatch))
122
123### config
124
125Type: `String`, `Object`
126Default: Path to nearest package.json
127
128### scope
129
130Type: `String`, `Array`
131Default: `['dependencies', 'devDependencies', 'peerDependencies']`
132
133
134## License
135
136[MIT](http://opensource.org/licenses/MIT) © [Sindre Sorhus](http://sindresorhus.com)