Search code examples
javascriptgulpwiredepgulp-inject

Gulp isn't running right


I have this tasks:

  • html:

    • transform .jade in .html
    • copy bower resources (css, js and fonts) to /dest/vendor folder
    • add bower resources to .html (script and link tags)
    • add my js (from /dest/js) and my css (from /dest/css) to .html (like prev.)
  • build

    • clean /dest folder
    • copy my js to /dest/js (just copy, no process)
    • process my less files, and move to /dest/css as css

if I run gulp build and then gulp html, everything works fine. But, if a add html as build last part, don't work more. Jade is transformed in a .html file, a all resources (my and bower) are copied to /dest folder, but wiredep and inject (that add script and link tags) appears do nothing.

This is (a part of) my tasks: https://gist.github.com/Falci/f52d4144318c9d5e4c2f


Solution

  • I see a couple potential issues with your build.

    1. You must return the stream from each task. Gulp relies on the return value of each task to determine when that task is finished. If you use a task without a return value as a dependency of another task, the dependency will be resolved immediately instead of waiting for the task to finish. You should use return values instead of using the next() callback.

      function htmlAssetsTask () {
          var sources = gulp.src(config.filesets.assetsDest, {read: false});
          return gulp.src(config.filesets.html)
          ...
      }
      
    2. Gulp task dependencies are not run in order. This means that in the task:

      gulp.task('build', ['clean:dest', 'build:js', 'build:less', 'html']);
      

      the dependencies can run in any order. I suggest using the run-sequence package to ensure the order of task dependencies when it is important.