0

I've got this gulp file

const gulp = require('gulp')
const sass = require('gulp-sass')
const cleanCSS = require('gulp-clean-css')
const rimraf = require('rimraf')
const concat = require('gulp-concat')

gulp.task('clean', function(cb) {
    rimraf('./dist/*', cb)
})

gulp.task('sass', function(cb) {
    gulp.src('./src/**/*.scss')
      .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
      .pipe(gulp.dest('./dist'))
    console.log('before')
    cb(undefined)
})

gulp.task('minify', function(cb) {
    gulp.src('./src/**/*.css')
      .pipe(cleanCSS())
      .pipe(gulp.dest('./dist'))
    console.log('before')
    cb(undefined)
})

gulp.task('build:css', ['sass', 'minify'], function() {
    gulp.src('./dist/**/*.css')
      .pipe(concat('style.min.css'))
      .pipe(gulp.dest('./dist'))
    console.log('after')
})

gulp.task('build', ['clean'], function() {
    gulp.start('build:css')
})

gulp.task('build:watch', function () {
    gulp.watch('./src/**/*.scss', ['build'])
})

But when I run build:watch

[11:26:18] Using gulpfile C:\dev\web\ikea_design\gulpfile.js
[11:26:18] Starting 'build:watch'...
[11:26:18] Finished 'build:watch' after 16 ms
[11:26:24] Starting 'clean'...
[11:26:24] Finished 'clean' after 11 ms
[11:26:24] Starting 'build'...
[11:26:24] Starting 'sass'...
before
[11:26:24] Finished 'sass' after 12 ms
[11:26:24] Starting 'minify'...
before
[11:26:24] Finished 'minify' after 2.27 ms
[11:26:24] Starting 'build:css'...
after
[11:26:24] Finished 'build:css' after 1.16 ms
[11:26:24] Finished 'build' after 25 ms

even if it displays the two befores before the after, style.css.min doesn't get created. That's strange since the css files should have already been saved in the dist folder by the time concat gets invoked.
What's wrong?

Edit

I've run gulp-debug inside of build:css and it shows 0 items in the pipe

  • Don't think it's related but you are running the minify task on the wrong folder: `gulp.src('./src/**/*.css')`, shouldn't it be `gulp.src('./dist/**/*.css')`? – Tomer Aug 31 '17 at 10:08
  • No, that's ok, because my `src` folder contains either `.sass` and `.css` files, and whilst the formers are compressed by `gulp-sass`, the ladders have to be minified somehow. And then, when everything is minified, I want to concatenate it – DoNotDownvote_JustUpvote Aug 31 '17 at 10:12
  • I found the solution at [this question](https://stackoverflow.com/questions/24619290/making-gulp-write-files-synchronously-before-moving-on-to-the-next-task). Since file writing is asynchronous, I've to make sure that it happens synchronously instead. – DoNotDownvote_JustUpvote Aug 31 '17 at 10:21

0 Answers0