Search code examples
javascripthtmlnode.jsgulp

Gulp3 to gulp 4 upgrade. Function with condition


Could you please help me with my problem? I'm trying to upgrade my gulpfile from 3 to 4 version. And I have this code

gulp.task('test', production() ? ['test2'] : null, function () {
// do something
});

gulp.task('test 2',  function () {
// do something
});

gulp.task('test4', gulp.series('test', 'test5'), function () {
// do something
});

And i have error - task test never defined. If i remove production() ? ['test2'] : null everything works fine


Solution

  • gulp.task expects only one argument for tasks, it should be not an array but gulp.series or gulp.parallel for composed task - which is already used in another task.

    It can be:

    gulp.task('test', gulp.series(...[
      production() && 'test2',
      function () { ... }
    ].filter(Boolean)));