11# Split tasks across multiple files
22
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 ) .
206
217Imagine the following file structure:
228
@@ -28,20 +14,25 @@ tasks/
2814└── test.js
2915```
3016
31- Install the ` require-dir ` module:
17+ Install the ` gulp-hub ` module:
3218
3319``` sh
34- npm install --save-dev require-dir
20+ npm install --save-dev gulp-hub
3521```
3622
3723Add the following lines to your ` gulpfile.js ` file:
3824
3925``` 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' );
4330
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+ ```
4437
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