Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run Gulp tasks sequentially one after the other

in the snippet like this:

gulp.task "coffee", ->     gulp.src("src/server/**/*.coffee")         .pipe(coffee {bare: true}).on("error",gutil.log)         .pipe(gulp.dest "bin")  gulp.task "clean",->     gulp.src("bin", {read:false})         .pipe clean             force:true  gulp.task 'develop',['clean','coffee'], ->     console.log "run something else" 

In develop task I want to run clean and after it's done, run coffee and when that's done, run something else. But I can't figure that out. This piece doesn't work. Please advise.

like image 553
iLemming Avatar asked Apr 02 '14 22:04

iLemming


People also ask

How do you signal async completion gulp?

To indicate to gulp that an error occurred in a task using an error-first callback, call it with an Error as the only argument. However, you'll often pass this callback to another API instead of calling it yourself.

How do I run a single gulp task?

In addition to making sure you have gulp globally installed, make sure your gulp file is named *gulpfile. js* and that is in the same directory as where you are running gulp . Then simply run gulp task1 .

What is gulp task runner?

Gulp is a task runner that uses Node. js as a platform. It purely uses the JavaScript code and helps to run front-end tasks and large-scale web applications. Gulp builds system automated tasks like CSS and HTML minification, concatenating library files, and compiling the SASS files.

How many types of streams are available gulp?

There are 5 types of streams are available in Gulp.


1 Answers

By default, gulp runs tasks simultaneously, unless they have explicit dependencies. This isn't very useful for tasks like clean, where you don't want to depend, but you need them to run before everything else.

I wrote the run-sequence plugin specifically to fix this issue with gulp. After you install it, use it like this:

var runSequence = require('run-sequence');  gulp.task('develop', function(done) {     runSequence('clean', 'coffee', function() {         console.log('Run something else');         done();     }); }); 

You can read the full instructions on the package README — it also supports running some sets of tasks simultaneously.

Please note, this will be (effectively) fixed in the next major release of gulp, as they are completely eliminating the automatic dependency ordering, and providing tools similar to run-sequence to allow you to manually specify run order how you want.

However, that is a major breaking change, so there's no reason to wait when you can use run-sequence today.

like image 182
OverZealous Avatar answered Nov 19 '22 14:11

OverZealous