Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • G gulp
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 24
    • Issues 24
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 3
    • Merge requests 3
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gulp
  • gulp
  • Issues
  • #1305
Closed
Open
Issue created Oct 04, 2015 by Administrator@rootContributor

Exports as tasks

Created by: jamiebuilds

One of the things I've started doing in all my gulpfiles is to write tasks as plain functions and then write gulp.task at the end of the file. This makes abstraction a bit easier and avoids using IDs for composition instead of just functions, making writing large complex gulpfiles much much easier to follow.

function test() { ... }
gulp.task('test', test);

This gets a lot easier with gulp 4 using series and parallel.

function test() { ... }
function buildFiles() { ... }
var build = gulp.series(test, buildFiles);
gulp.task('test', test);
gulp.task('build', build);

But at this point writing out gulp.task seems a bit unnecessary since the id isn't being used in the code and is only there to export a set of tasks.

I'd prefer just to write:

exports.test = test;
exports.build = build;

Now this gets even more interesting with ES2015 because you can write:

export function test() { ... }
export function build() { ... }

One of the cool benefits here is that you can use static analysis to determine which tasks the gulpfile defines and use it for stuff like CLI autocompletion:

$ gulp [tab]
  - test
  - build
  - dev

But the bigger benefit here is that it encourages people to write gulp tasks as plain functions that return streams, making them far more generic and simplifying the gulp API greatly.

This is what gulpfiles could look like in the future: https://gist.github.com/thejameskyle/2778e4df363612635989

How would you all feel about allowing tasks to be defined as exports?

Assignee
Assign to
Time tracking