Closed amoldavsky closed 5 years ago
If you want to use gulp in this way (not daisy-chaining), shouldn't you be assigning the results of your pipe operations to task? I don't think it's (supposed to be) mutable.
i.e.
task = task.pipe(project());
task = task.pipe(gulp.dest('build'));
task = task.pipe( debug({ title: 'build-scripts' }) );
Gulp wasn't designed to handle streams like this. It might work on some plugins, as some plugins mutate objects. The first plugin would mutate the file object (synchronously), and the handler of the second plugin would then get the mutated object as input. This requires that the plugins work synchronously, as the next plugin will be invoked directly afterwards.
Ignoring the question whether it is a good idea to modify those objects instead of creating new ones, we simply cannot do that, for several reasons:
.js
and .d.ts
)The solution by Sam is a good alternative. I would suggest to use the normal way of chaining if possible. If you for instance have some logic to determine which plugins you need to apply, you could store the result in a variable.
Expected behavior: expecting to get a *.js file in output
Actual behavior: getting a *.ts file in output
Your gulpfile:
any other gulp script / lib i run in this fashion seems to work fine. And the reason why i do not chain is because in the actual use case i have conditionals in which i would add more steps to a task based on some CLI parms.
Regardless of anything, wether chaining or separating this should have absolutely no difference, gulp task was intended to work either way and the support imo has to be there whether this does or does not makes sense to do it this way.