question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update Gulp 4 recipe for splitting tasks between multiple files

See original GitHub issue

TL;DR - Define composite tasks in gulpfile after gulp.registry(hub)


Split tasks across multiple files has been updated to use the new gulp-hub module, but with the Gulp 4 registry forward referencing tasks is no longer possible.

While sequencing is still being discussed in #972 and (prior to that) #802, I’ve created a test repo with a basic example of splitting tasks across multiple files with a slightly modified recipe.

https://github.com/bradcerasani/gulp-4--split-tasks

Description

Standalone tasks are defined in the tasks directory, and gulp-hub is used to create a new registry. Tasks that use a combination of sub-tasks are now defined in the gulpfile, after gulp.registry

While this will require a minor restructuring of tasks in some projects, I actually prefer defining composite tasks like default, watch, and build in my gulpfile and using the tasks directory strictly for standalone tasks. In larger gulpfiles composite tasks are typically short and called far more frequently than their standalone siblings, so IMO it’s easier to reference them in one place.

File structure (unchanged):

gulpfile.js
tasks/
├── clean.js
└── scripts.js

gulpfile.js

'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);

// define composite tasks
gulp.task('default', gulp.series('clean', 'scripts'));

If this is a viable solution, I’m happy to submit a PR with an updated recipe.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:15 (7 by maintainers)

github_iconTop GitHub Comments

17reactions
phatedcommented, Jan 9, 2017

Please stop spamming our projects. An upgrade path has already been developed.

3reactions
mikestopcontinuescommented, Jun 2, 2015

@phated, I really appreciate you putting thought into my case, though I just don’t understand the reasoning behind the current implementation. As it stands, I’d rather just monkey-patch .series and .parallel for lazy task lookup because it’ll also allow me to load a directory of tasks, which is another big convenience of how I do things now. But maybe I’m just missing something? I’d love to hear your reasoning for early task lookup rather than at runtime.

(My own gulp3-based .parallel and .series functions accept regex objects for lookup at runtime. This way, my build task does /build…*$/, which for some projects matches the global “build.css” and “build.js”, but in particular projects also matches the local “build.font” or “build.html” in their local tasks directories.)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gulp 4 Split Tasks Across Multiple Files Using Gulp-Hub Fails ...
Using Gulp 4 and the recipe for splitting my tasks into multiple files using gulp-hub throws this error just from attempting to load...
Read more >
The Complete-Ish Guide to Upgrading to Gulp 4
The “tasks” can be split into multiple files and easily imported into a single file that uses gulp. task to define the runnable...
Read more >
Splitting a gulpfile into multiple files - Callum Macrae
This approach literally involves moving a task to each file and is the approach detailed in the recipe in the Gulp repository: gulp-tasks/ ......
Read more >
JavaScript and Gulpfiles - gulp.js
Many users start by adding all logic to a gulpfile. If it ever grows too big, it can be refactored into separate files....
Read more >
Gulp for Beginners | CSS-Tricks
gulp.src tells the Gulp task what files to use for the task, ... Most workflows with Gulp tend to only require 4 different...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found