UNPKG

3.19 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`/`optionalDependencies` in your package.json and load grunt tasks that match the provided patterns.
8
9#### Before
10
11```js
12grunt.loadNpmTasks('grunt-shell');
13grunt.loadNpmTasks('grunt-sass');
14grunt.loadNpmTasks('grunt-recess');
15grunt.loadNpmTasks('grunt-sizediff');
16grunt.loadNpmTasks('grunt-svgmin');
17grunt.loadNpmTasks('grunt-styl');
18grunt.loadNpmTasks('grunt-php');
19grunt.loadNpmTasks('grunt-eslint');
20grunt.loadNpmTasks('grunt-concurrent');
21grunt.loadNpmTasks('grunt-bower-requirejs');
22```
23
24#### After
25
26```js
27require('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
42module.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
57require('load-grunt-tasks')(grunt);
58```
59
60Equivalent to:
61
62```js
63require('load-grunt-tasks')(grunt, {pattern: ['grunt-*', '@*/grunt-*']});
64```
65
66### Load all grunt-contrib tasks
67
68```js
69require('load-grunt-tasks')(grunt, {pattern: 'grunt-contrib-*'});
70```
71
72### Load all grunt-contrib tasks and another non-contrib task
73
74```js
75require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', 'grunt-shell']});
76```
77
78### Load all grunt-contrib tasks excluding one
79
80You can exclude tasks using the negate `!` globbing pattern:
81
82```js
83require('load-grunt-tasks')(grunt, {pattern: ['grunt-contrib-*', '!grunt-contrib-coffee']});
84```
85
86### Set custom path to package.json
87
88```js
89require('load-grunt-tasks')(grunt, {config: '../package'});
90```
91
92### Only load from `devDependencies`
93
94```js
95require('load-grunt-tasks')(grunt, {scope: 'devDependencies'});
96```
97
98### Only load from `devDependencies` and `dependencies`
99
100```js
101require('load-grunt-tasks')(grunt, {scope: ['devDependencies', 'dependencies']});
102```
103
104### All options in use
105
106```js
107require('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
120Type: `string | string[]`<br>
121Default: `['grunt-*', '@*/grunt-*']` ([Glob pattern](https://github.com/isaacs/minimatch))
122
123### config
124
125Type: `string | object`<br>
126Default: Path to nearest package.json
127
128### scope
129
130Type: `string | string[]`<br>
131Default: `['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']`<br>
132Values: `'dependencies'`, `'devDependencies'`, `'peerDependencies'`, `'optionalDependencies'`, `'bundledDependencies'`
133
134### requireResolution
135
136Type: `boolean`<br>
137Default: `false`
138
139Traverse 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.