I'm upgrading from v3 to v4 of Gulp, and can no longer define tasks dynamically.
How do I go about his in V4 of Gulp?
NOTE: Tasks are split into different files, and the reason for the dynamic name is the use of a template.
What were you expecting to happen?
I would expect to be able to define a task dynamically like this (worked fine in v3):
gulp.task( module_name + 'scss', gulp.parallel([scss], function () {
...
}));
What actually happened?
The dynamic name is no longer defined (registered as a task):
AssertionError [ERR_ASSERTION]: Task never defined: indexscss
Please post a sample of your gulpfile (preferably reduced to just the bit that's not working)
…
const gulp = require('gulp');
let module_name = 'index';
if ( args.watch > -1 ) {
…
gulp.watch([ scss_source ], gulp.parallel(module_name + 'scss'));
}
gulp.task( module_name + 'scss', gulp.parallel([scss], function () {
…
}));
function scss () {
return gulp.src( scss_source ) // scss_source defined elsewhere
…
}
module.exports = (function () {
…
scss();
…
}());
What version of gulp are you using?
CLI version 2.0.1
Local version 4.0.0
What versions of npm and node are you using?
npm 6.1.0
node 9.0.0
This seems to be the bugger:
gulp.watch([ scss_source ], D.gulp.parallel(module_name + 'scss'));
SOLUTION (of sorts)
Well, after writing the rather lengthy post (and continuously trying stuff out) it turned out that all I had to do was put the (task) definitions BEFORE the watch.
So this means that hoisting it pulled out of the game in Gulp v4, or what?
You are trying to use patterns that are no longer supported. They were never recommended and you were only able to do this incidentally to how some internals were implemented.
I'd suggest reading through the entire Getting Started guide to get acquainted with the up-to-date recommended patterns.