Gulp task does not rotate (but turns callback)

Asked

Viewed 84 times

3

I have a task in Gulp, defined more or less like this:

gulp.task('tarefa', ['a', 'b', 'c'], function () {
   console.log("tarefa executada com sucesso");
});

From what I understand of documentation, this code should do the following:

  • Set the name task "task";
  • Running tasks in parallel "to", "b" and "c";
  • After the tasks are completed "to", "b" and "c", execute the logic defined for the task.

What really happens:

  • The name task is defined task;
  • The tasks "to", "b" and "c" are executed in parallel;
  • The program stops, indicating success, but the logic I set for the task task is not executed.

However, I noticed that if in other tasks I receive a parameter, and treat this parameter as a function... For example:

gulp.task('a', function (callback) {
    callback();
});

The callback above is the function I set as task body task.

I would like to run my task only after the others have run, and as they will run in parallel, I cannot use my function as callback of the other tasks.

What I must do?

1 answer

1


We can indicate in a task which is its dependency, that is, which task should be executed before.

see this example that the copy task waits for the clean task to finish running:

// adicionando clean como dependência da tarefa copy

//na tarefa copy passo ['clean']

gulp.task('copy', ['clean'], function() {
    gulp.src('src/**/*')
        .pipe(gulp.dest('dist'));
});

//na tarefa clean passo return
gulp.task('clean', function(){
    return gulp.src('dist')
        .pipe(clean());   
});

Note that tasks are executed one at a time, because in this context it does not make sense that they are executed in parallel

Browser other questions tagged

You are not signed in. Login or sign up in order to post.