Search code examples
javascriptperformancereturngulplibsass

Gulp sass (libsass) extremely slow when using return


I'm new to Gulp (and not very comfortable with js). When I use

gulp.task('sass', function () {
  gulp
    .src('myfile.scss')
    .pipe(sourcemaps.init())
    .pipe(sass(myoptions))
    .pipe(sourcemaps.write('./'))
    .pipe(gulp.dest('mypath'))
    .pipe(browserSync.stream({match: '**/*.css'}));
});

compilation is made in a few ms

But When i use

gulp.task('sass', function () {
  return gulp
    ...
});

it take several seconds to compile.

Can someone explain me why ?

Thanks.


Solution

  • Gulp uses orchestrator to execute the tasks. Your task returns a promise or a stream (in your case it's a stream), which is used for sequencing.

    When you return nothing, the caller can't know that your task isn't finished, which has at least 2 impacts:

    • you may think it's finished (from the log) before it really is
    • following tasks may start too soon, and might even use an old version of the compiled CSS data