Home > Web Front-end > JS Tutorial > body text

How to Execute Gulp Tasks Sequentially?

Mary-Kate Olsen
Release: 2024-10-28 01:54:02
Original
548 people have browsed it

How to Execute Gulp Tasks Sequentially?

Running Gulp Tasks Sequentially

In Gulp, tasks are typically run simultaneously. However, sometimes you may want to run tasks sequentially, such as ensuring that a clean task is completed before starting a coffee task.

In the provided code snippet, the "develop" task intends to run the "clean" task, followed by the "coffee" task, and finally, executing "run something else":

<code class="javascript">gulp.task('develop', ['clean', 'coffee'], ->
  console.log "run something else"
)</code>
Copy after login

However, this doesn't work as expected due to Gulp's default parallel execution. To address this, you can use the run-sequence plugin:

<code class="javascript">var runSequence = require('run-sequence')

gulp.task('develop', ->
  runSequence('clean', 'coffee', ->
    console.log 'Run something else'
  )
)</code>
Copy after login

The run-sequence plugin allows you to specify the order of task execution. By utilizing this plugin, you can enforce the desired sequential execution in the "develop" task:

  1. Clean
  2. Coffee
  3. Run something else

Alternatively, you can wait for the completion of each task before proceeding to the next one:

<code class="javascript">var gulp = require('gulp')
var gutil = require('gutil')

gulp.task('clean', ->
  gulp.src('bin', {read: false})
    .pipe(clean({force: true}))

gulp.task('coffee', ->
  gulp.src('src/server/**/*.coffee')
    .pipe(coffee {bare: true})
    .on('error', gutil.log)
    .pipe(gulp.dest('bin'))

gulp.task('develop', ['clean'], ->
  gulp.start('coffee')

gulp.task('develop:all', ['develop'], ->
  console.log 'Run something else'
)</code>
Copy after login

By chaining tasks and including dependencies explicitly, you can achieve sequential task execution in Gulp.

The above is the detailed content of How to Execute Gulp Tasks Sequentially?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!