B
B
BarneyGumble2018-02-06 12:32:10
JavaScript
BarneyGumble, 2018-02-06 12:32:10

How to run a task in Gulp only after other tasks have completed?

Hello, I have the following gulpfile.js:

var gulp = require('gulp'),
    sass = require('gulp-sass'), 
    concatcss = require('gulp-concat'),
    clean = require('gulp-clean'),
    plumber = require('gulp-plumber');

// Собирает все scss файлы в директории blocks и склеивает их в один
gulp.task('blocks', function() {
    return gulp.src('app/scss/blocks/**/*.scss')
        .pipe(plumber())
    	.pipe(concatcss("_blocks.scss"))
    	.pipe(gulp.dest('app/scss/build/'));
});

// Запускает генерацию финального css файла из имеющихся scss
gulp.task('sass', function() {
    return gulp.src('app/scss/main.scss')
        .pipe(plumber())
        .pipe(sass())
        .pipe(gulp.dest('app/css'))
});

// Очищает результирующий файл сборки для последующей записи в него
gulp.task('clean', function () {  
    return gulp.src('app/scss/build/_blocks.scss', {read: false})
        .pipe(clean());
});


gulp.task('watch', function() {
    gulp.watch(['app/scss/**/*.scss'], ['clean']);
    gulp.watch(['app/scss/blocks/**/*.scss'], ['blocks']);
    gulp.watch(['app/scss/**/*.scss'], ['sass']);
});

Contents of app/scss/main.scss:
@import 'vendors/normalize';
@import 'utils/variables';
@import 'base/fonts';
@import 'utils/placeholders';
@import 'build/blocks';
@import 'base/media';

When saving a file in the app/blocks directory, I get the following error:
Error in plugin 'gulp-sass'
Message:
    app\scss\main.scss
Error: File to import not found or unreadable: build/blocks.
       Parent style sheet: C:/Users/kalashnikov/Desktop/layout/relaxlux/app/scss/main.scss
        on line 5 of app/scss/main.scss

As I understand it, the console tells me that it cannot read the blocks.scss file, because it is probably trying to read it at the moment when the clean task deleted it , and the blocks task has not yet had time to work out
Is this true and if so, how can I run sass task only after other tasks have completed?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
enchikiben, 2018-02-06
@BarneyGumble

gulp.task('watch', function() {
    gulp.watch(['app/scss/**/*.scss'], ['clean','blocks','sass']);
});

and so?

S
Socrates, 2018-02-06
@Karmov69

He seems to include them in order

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question