Patrick Kenny
Patrick Kenny

Reputation: 6397

Using gulp.series with a gulp task that has a callback

I'm trying to use gulp.series to generate all my build assets at once for CircleCI.

const circleciBuild = gulp.series(styles, js, generate-favicon)

lando gulp circleciBuild fails with the message:

ReferenceError: generate is not defined

But it is defined in the gulpfile:

gulp.task('generate-favicon', function(done) {
  realFavicon.generateFavicon({
  // Long function
  }, function() {
    done();
  });

});

I tried changing the function's name to generateTheFavicon, but then I get the error:

ReferenceError: generateTheFavicon is not defined

I'm guessing this has something to do with the way the task is defined, because js and styles are function js() and function styles(), whereas the problem function is gulp.task. How can I rewrite a gulp.task function to use it in gulp.series?

This might be easy, but I'm new to gulp and not very good with js.

Upvotes: 0

Views: 640

Answers (1)

Mark
Mark

Reputation: 181050

Since you are using this style of defining tasks:

gulp.task('generate-favicon',...

Then you will always refer to those tasks as their string names. So

const circleciBuild = gulp.series(styles, js, 'generate-favicon')

You don't show your other tasks so I don't know how they are defined.

If instead you used this form:

function generate-favicon ()  {...

then you wouldn't refer to them as strings, just their function names so

const circleciBuild = gulp.series(styles, js, generate-favicon)

would be correct. For other reasons, like passing arguments this later function name method is the recommended way to do it.

Upvotes: 1

Related Questions