0

I'd like to create a watcher to watch some files and compile them.

I have two tasks :

  • minCss
  • compile

I'd like to execute compile in first and wait the end before executing minCss... But it seem's not working.

My code :

var scssToCompile = [
   './public/sass/themes/adms/adms.scss',
   './public/sass/themes/arti/arti.scss',
   './public/sass/themes/avantage/avantage.scss',
   './public/sass/themes/basique/basique.scss',
   './public/sass/themes/mairie/mairie.scss',
   './public/sass/themes/vehik/vehik.scss',
   './public/sass/themes/concept/concept.scss',
   './public/sass/themes/news/news.scss',
   './public/sass/components/*.scss',
   './public/sass/_functions.scss',
   './public/sass/_settings.scss',
   './public/sass/app.scss',
   './public/sass/bottom.scss'
];

gulp.task('compile', function(){
  return gulp.src(scssToCompile)
    .pipe(sassGlob())
    .pipe(sass({includePaths: ['./public/sass']}).on('error', function(err) {
      cb(err);
    }))
    .pipe(gulp.dest('./public/stylesheets'));
});

gulp.task('minCss', function() {
  return gulp.src('public/stylesheets/themes/**/*.css')
    .pipe(minifyCss())
    .pipe(rename({suffix: '.min'}))
    .pipe(gulp.dest('public/build/css'));
});

// my watcher
gulp.task('watch', function(){
  gulp.watch(scssToCompile, ['compile', 'minCss']);
});

Results :

[15:21:36] Using gulpfile C:\xampp\htdocs\gulpfile.js
[15:21:36] Starting 'watch'...
[15:21:37] Finished 'watch' after 153 ms
[15:21:41] Starting 'compile'...
[15:21:46] Starting 'minCss'...
[15:21:46] Finished 'minCss' after 6.42 μs
[15:21:48] Finished 'compile' after 6.44 s
tonymx227
  • 5,293
  • 16
  • 48
  • 91
  • Duplicate of [How to run Gulp tasks sequentially one after the other](http://stackoverflow.com/questions/22824546/how-to-run-gulp-tasks-sequentially-one-after-the-other) – Sven Schoenung Nov 17 '16 at 14:39
  • It doesn't work with `cb()`, I don't know how to separate the tasks... – tonymx227 Nov 17 '16 at 14:54
  • What are you talking about? You don't need to call `cb()` or separate your tasks. The answers in that question are 100% applicable for your use case. – Sven Schoenung Nov 17 '16 at 15:12

0 Answers0