2

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.

Chuck Norris
  • 1,125
  • 1
  • 12
  • 28

1 Answers1

5

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
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • Ok, thanks for the answer ... so its best to return a promises. Now i just have to check why its so long to compile my scss files. – Chuck Norris Jan 22 '16 at 10:21
  • Hard to tell but for me it's a few ms for a dozen scss files (I don't use browserSync, are you sure it isn't what takes time ?). – Denys Séguret Jan 22 '16 at 11:08
  • Ok, juste find out. The "problem" is coming from the sass options object **.pipe(sass(options))**, `options = {outputStyle: 'compressed'}` or `options = {}` . when i disable this line, compilation is very fast, but when i set options (even if options object is empty) compilation take foreever. Is there any reason for this? – Chuck Norris Jan 22 '16 at 12:24
  • @ChuckNorris I don't reproduce that. Compilation speed doesn't change for me when I pass an empty object instead of nothing. – Denys Séguret Jan 22 '16 at 12:40