Phong Duong


Run task in sequential order in Gulpjs

01-10-2020 | #gulpjs

Gulpjs allows you to group your tasks into compositions and execute them as public tasks. series() function receives your tasks as an array or arguments. You can use series() function with parallel() function.

When you pass your tasks to the serires() function, you need to notice the order they execute.

Let's create 2 tasks and pass them to the series()

const { src, dest, series } = require("gulp");

const copyCSS = () => {
  return src(["./**/*.css", "!{node_modules,dist}/**"]).pipe(dest("dist"));

const copyPNG = () => {
  return src("src/**/*.png").pipe(dest("dist"));

exports.default = series([copyCSS, copyPNG]);

When you run gulp command, you see that copyPNG only runs after copyCSS finishes. After the last task finishes, the command will exit.

Share: TwitterFacebookLinkedInHacker News