Skip to content

Commit

Permalink
Docs: Update "split tasks" recipe to use gulp-hub
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Dec 31, 2017
1 parent 6c46116 commit f7e7d4c
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions docs/recipes/split-tasks-across-multiple-files.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
# Split tasks across multiple files

If your `gulpfile.js` is starting to grow too large, you can split
the tasks into separate files using one of the methods below.

> Be advised, that this approach is [considered deprecated][deprecated]
> and could lead to problems when migrating to the `gulp 4`.

## Using `gulp-require-tasks`

You can use the [gulp-require-tasks][gulp-require-tasks]
module to automatically load all your tasks from the individual files.

Please see the [module's README][gulp-require-tasks] for up-to-date instructions.

## Using `require-dir`

You can also use the [require-dir][require-dir] module to load your tasks manually.
If your `gulpfile.js` is starting to grow too large, you can split the tasks
into separate files by using the [gulp-hub](https://github.com/frankwallis/gulp-hub/tree/4.0)
module as a [custom registry](https://github.com/phated/undertaker#registryregistryinstance).

Imagine the following file structure:

Expand All @@ -28,20 +14,25 @@ tasks/
└── test.js
```

Install the `require-dir` module:
Install the `gulp-hub` module:

```sh
npm install --save-dev require-dir
npm install --save-dev gulp-hub
```

Add the following lines to your `gulpfile.js` file:

```js
var requireDir = require('require-dir');
var tasks = requireDir('./tasks');
```
'use strict';

var gulp = require('gulp');
var HubRegistry = require('gulp-hub');

/* load some files into the registry */
var hub = new HubRegistry(['tasks/*.js']);

/* tell gulp to use the tasks just loaded */
gulp.registry(hub);
```

[gulp-require-tasks]: https://github.com/betsol/gulp-require-tasks
[require-dir]: https://github.com/aseemk/requireDir
[deprecated]: https://github.com/gulpjs/gulp/pull/1554#issuecomment-202614391
This recipe can also be found at https://github.com/frankwallis/gulp-hub/tree/4.0/examples/recipe

0 comments on commit f7e7d4c

Please sign in to comment.