Now working with Gulp you will discover that you run into a couple of minor problems. Especially in sequencing the different types of tasks.
Lets take a simple clean task, it should run before all of the other tasks. However Gulp will run all tasks in parallel.

The team that is working on Gulp has been working on a solution for this problem and in Gulp 4.0 we will get gulp.series() and gulp.parallel(); to distinguish between these two types of operations.

Sadly it looks like that currently the release of Gulp 4.0 is delayed. However you can use the current Alpha version prior to its release.

Installing Gulp 4

You can simply install the next version of Gulp with NPM (A git client is required, as the package is not in the npm repository and will be cloned from Github)

Updating the gulpfile.js

The syntax for tasks has changed, so we need to rewrite parts of the file:
Our exisiting Gulp 3 task

Needs to be rewritten with gulp parallel as such:

However we should not stop there and improve upon this task, by running the clean task before all of the other tasks. To ensure that it runs before the other tasks we use gulp.series().

Improving on the production flag

With gulp.series() we now can stop using the –production flag. We simply define a production task.

As first operation we pass in a function that simply sets the production boolean to true:

The function uses “done” to signal gulp that the function has completed.

Hiding Tasks

Another improvement of Gulp 4.0 is that you can pass functions, as well as tasks to gulp.series and gulp.parallel.

This in turn lets you write normal functions that are hidden from the command line, ensuring that everybody on the project runs the default build task instead of only the html task.

Here is now our improved Gulpfile.js:

Package.json