Friday, 17 March 2017

How to create a "rebuild" task in gulp?

gulp.task('build', function () {
  // Build, generate files...
});

gulp.task('clear', function () {
  // Delete generated files.
});

gulp.task('rebuild', function () {
  // First: clear
  // Then: build
});

In most case, "build" task doesn't need previous generated files to be removed (which slows the build process).

But there is times when I want to run "clear" and "build" task in one command:

Of course "rebuild" task depends on "clear" and "build", but if I use dependency hint like

gulp.task('rebuild', ['clear', 'build']);

the two tasks run asynchronously, which results in unexpected problem!


The easy way to solve this problem is run:

gulp clear
gulp build

but a single command

gulp rebuild

is easier, right? :P

By the way, gulp.series() has been deprecated...



via zjuwujunchao

No comments:

Post a Comment