Gulp.js task ends before all files all processed

100 views Asked by At

I want to use gulp-inject at the end of my build process to include all javascript files in html. I want to use CI so my target is to always start from clearing output directory and generate brand new version of public directory. The problem is that my build is quite slow - I use both angular.js and cofee script on many files. My task looks like that:

gulp.task 'coffee', () ->
     gulp.src files
        .pipe $.flatten()
        .pipe $.if(!argv.production, $.sourcemaps.init())
        .pipe $.coffee().on 'error', (err) -> console.log(err)
        .pipe $.ngAnnotate()
        .pipe gulp.dest JS_OUTPUT

And unfortunately, files are processed long after build is done - I have many of them, and operation on each is quite long time. They are not existing when gulp-inject is started.

Why gulp.js task ends even if files all still processing?

1

There are 1 answers

3
Ghidello On

I'm not sure if your sample, translated to javascript, returns something or not: returning a stream is one of the ways gulp has to know if a task has been completed or not.

You may read this recipe: running-tasks-in-series. It has been very useful to me to understand the basics without reading the docs.. :D