1

According to https://gulpjs.com/docs/en/api/task the new way to create tasks is not gulp.task("xyz" ...) but instead use exports.build = build; The problem with this approach is, that I can't use old task names like feature:build, feature:watch anymore, because I can only export valid JS identifiers.

Is there any way to achieve this with the new method?

totkeks
  • 89
  • 2
  • 9

4 Answers4

1

This is a very basic question. Use the syntax exports[taskName] = taskFunction;, for example

exports['feature:build'] = function () {
   // ...
};

You may want to read more here: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Basics#Bracket_notation

GOTO 0
  • 42,323
  • 22
  • 125
  • 158
  • Thanks for your reply. You are right, but I noticed I didn't properly ask my question. I'm using gulp with typescript and the default way to export there is just `export foo`. – totkeks Aug 03 '19 at 14:05
1

Found the answer by accident.

Each TaskFunction has a property displayName, which does not just change the name that is used to display the task in the task list or when running, but also the task name that you need to pass gulp in order to run it.

So it would be something like:

export const myTask :TaskFunction = () => ...;
myTask.displayName = "run:task";
totkeks
  • 89
  • 2
  • 9
0

The good news is: Starting with ECMAScript 2022, it is possible to alias exports with string literals:

function featureBuild() { ... }

export {
    featureBuild as 'feature:build'
}

See section 16.2.3, where the export syntax is defined, you will see that ModuleExportName may be a string literal.

The bad news is: I could not find any software that already implements this.

jlh
  • 4,349
  • 40
  • 45
  • Thanks for checking back in my question after many years. I haven't tried it yet, but maybe typescript supports or will support it in the near future? – totkeks Jul 13 '22 at 15:22
0

The simplest way I found is just to add the function to the exports and execute it via Terminal.

In the gulpfile.js:

exports.your_function = ....

and in the Terminal:

> gulp your_function

Hope it helps.