Gulp task does not run (but becomes callback)

Question:

I have a task in gulp, defined something like this:

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

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

  • Define the task named "task" ;
  • Run tasks "a" , "b" and "c" in parallel;
  • After completing tasks "a" , "b" and "c" , execute the logic defined for the task.

What actually happens:

  • The task named task is defined;
  • Tasks "a" , "b" and "c" run in parallel;
  • The program stops, indicating success, but the logic I defined for the task task is not executed.

However, I noticed that if in the 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 defined as task body task .

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

What should I do?

Answer:

We can indicate in a task what its dependency is, that is, which task must be performed first.

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

// 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());   
});

See that the tasks are executed one at a time, because in this context it makes no sense to run them in parallel

Scroll to Top