在开始下一个任务之前等待prev任务

时间:2016-11-17 14:26:08

标签: gulp

我想创建一个观察者来观看一些文件并进行编译。

我有两个任务:

  • minCss
  • 编译

我想首先执行compile并在执行minCss之前等待结束......但它似乎无法正常工作。

我的代码:

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']);
});

结果:

[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

0 个答案:

没有答案