Reputation: 99
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?
Upvotes: 1
Views: 861
Reputation: 4667
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.
EDIT: Node 18.20 and 20.11 understand this syntax. PhpStorm 2023.3.6 still doesn't.
Upvotes: 0
Reputation: 11
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.
Upvotes: 0
Reputation: 99
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";
Upvotes: 1
Reputation: 47614
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
Upvotes: 1