title: Gulp having to save twice to work
body: <p>I've been developing a program with gulp to automatically minify my entire project and copy everything of an src folder to an dist folder (where the minified files stay), so i can generate an war file after with this minified files.</p>
  
  <p>I'm watching the src files for changes and then, on every change i clean the dist folder, minify the files and copy then to the dist folder, but the problem is, every time i change a file and save, it cleans the dist folder, but doesn't copy the minified files to a new dist folder, only when i save for a second time, the dist folder is created again and the minified files are copied to it.</p>
  
  <p>This is my code so far.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var gulp = require('gulp');
  var inject = require('gulp-inject');
  var webserver = require('gulp-webserver');
  var htmlclean = require('gulp-htmlclean');
  var cleanCSS = require('gulp-clean-css');
  var uglify = require('gulp-uglify');
  var del = require('del');
  var war = require('gulp-war');
  var zip = require('gulp-zip');
  var gulpSequence = require('gulp-sequence');
  
  var paths = {
      src: 'src/**/*',
      srcHTML: 'src/**/*.html',
      srcCSS: 'src/**/*.css',
      srcJS: 'src/**/*.js',
  
      tmp: 'tmp',
      tmpIndex: 'tmp/index.html',
      tmpCSS: 'tmp/**/*.css',
      tmpJS: 'tmp/**/*.js',
  
      dist: 'dist',
      distIndex: 'dist/index.html',
      distCSS: 'dist/**/*.css',
      distJS: 'dist/**/*.js'
  };
  
  gulp.task('default', ['watch']);
  
  gulp.task('serve', function () {
      return gulp.src(paths.tmp)
          .pipe(webserver({
              port: 3000,
              livereload: true
          }));
  });
  
  gulp.task('watch', ['serve'], function () {
      gulp.watch(paths.src, function (event) {
          gulpSequence('clean', 'copy:dist', 'inject:dist')(function (err) {
              if (err) {
                  console.log(err);
              }
          });
      });
  });
  
  gulp.task('html:dist', function () {
      console.log('htmlMin');
      return gulp.src(paths.srcHTML)
          .pipe(htmlclean())
          .pipe(gulp.dest(paths.dist));
  });
  
  gulp.task('css:dist', function () {
      console.log('cssMin');
      return gulp.src(paths.srcCSS)
          .pipe(cleanCSS())
          .pipe(gulp.dest(paths.dist));
  });
  
  gulp.task('js:dist', function () {
      console.log('jsMin');
      return gulp.src(paths.srcJS)
          .pipe(uglify())
          .pipe(gulp.dest(paths.dist));
  });
  
  gulp.task('copy:dist', ['html:dist', 'css:dist', 'js:dist'], function () {
      console.log('Copy');
  });
  
  gulp.task('inject:dist', function () {
      var css = gulp.src(paths.distCSS);
      var js = gulp.src(paths.distJS);
      console.log('Inject');
      return gulp.src(paths.distIndex)
          .pipe(inject(css, { relative: true }))
          .pipe(inject(js, { relative: true }))
          .pipe(gulp.dest(paths.dist));
  });
  
  gulp.task('build', ['inject:dist']);
  
  gulp.task('clean', function () {
      console.log('Clean');
      del([paths.tmp, paths.dist]);
  });
  
  gulp.task('war', function () {
      gulp.src([paths.dist])
          .pipe(war({
              welcome: 'index.html',
              displayName: 'Grunt WAR',
          }))
          .pipe(zip('myApp.zip'))
          .pipe(gulp.dest("./dist"));
  });</code></pre>
  </div>
  </div>
  </p>