1
1
# Split tasks across multiple files
2
2
3
- If your ` gulpfile.js ` is starting to grow too large, you can split
4
- the tasks into separate files using one of the methods below.
5
-
6
- > Be advised, that this approach is [ considered deprecated] [ deprecated ]
7
- > and could lead to problems when migrating to the ` gulp 4 ` .
8
-
9
-
10
- ## Using ` gulp-require-tasks `
11
-
12
- You can use the [ gulp-require-tasks] [ gulp-require-tasks ]
13
- module to automatically load all your tasks from the individual files.
14
-
15
- Please see the [ module's README] [ gulp-require-tasks ] for up-to-date instructions.
16
-
17
- ## Using ` require-dir `
18
-
19
- You can also use the [ require-dir] [ require-dir ] module to load your tasks manually.
3
+ If your ` gulpfile.js ` is starting to grow too large, you can split the tasks
4
+ into separate files by using the [ gulp-hub] ( https://github.com/frankwallis/gulp-hub/tree/4.0 )
5
+ module as a [ custom registry] ( https://github.com/phated/undertaker#registryregistryinstance ) .
20
6
21
7
Imagine the following file structure:
22
8
@@ -28,20 +14,25 @@ tasks/
28
14
└── test.js
29
15
```
30
16
31
- Install the ` require-dir ` module:
17
+ Install the ` gulp-hub ` module:
32
18
33
19
``` sh
34
- npm install --save-dev require-dir
20
+ npm install --save-dev gulp-hub
35
21
```
36
22
37
23
Add the following lines to your ` gulpfile.js ` file:
38
24
39
25
``` js
40
- var requireDir = require (' require-dir' );
41
- var tasks = requireDir (' ./tasks' );
42
- ```
26
+ ' use strict' ;
27
+
28
+ var gulp = require (' gulp' );
29
+ var HubRegistry = require (' gulp-hub' );
43
30
31
+ /* load some files into the registry */
32
+ var hub = new HubRegistry ([' tasks/*.js' ]);
33
+
34
+ /* tell gulp to use the tasks just loaded */
35
+ gulp .registry (hub);
36
+ ```
44
37
45
- [ gulp-require-tasks ] : https://github.com/betsol/gulp-require-tasks
46
- [ require-dir ] : https://github.com/aseemk/requireDir
47
- [ deprecated ] : https://github.com/gulpjs/gulp/pull/1554#issuecomment-202614391
38
+ This recipe can also be found at https://github.com/frankwallis/gulp-hub/tree/4.0/examples/recipe
0 commit comments