How to compile SASS files in different directories using Gulp?

Leon Gaban picture Leon Gaban · Feb 14, 2015 · Viewed 7.9k times · Source

I'm using gulp-ruby-sass to compile my js and sass.

I ran into this error first TypeError: Arguments to path.join must be strings

Found this answer and it was because I was using sourcemaps with gulp-sass and the answer recommended using gulp-ruby-sass instead.

Next I tried to compile all my SASS files using this syntax:

gulp.task('sass', function () {
    return sass('public/_sources/sass/**/*.scss', { style: 'compressed' })
        .pipe(sourcemaps.init())
        .pipe(concat('bitage_public.css'))
        .pipe(sourcemaps.write('./maps'))
        .pipe(gulp.dest('public/_assets/css'))
        .pipe(livereload());
});

Which produced this error: gulp-ruby-sass stderr: Errno::ENOENT: No such file or directory - public/_sources/sass/**/*.scss

I then noticed in the answer I found the author wrote that globes ** aren't supported yet:

Also keep in mind, as of this writing when using gulp-ruby-sass 1.0.0-alpha, globs are not supported yet.

I did more digging and found a way to use an Array to specify the paths to my SASS files, so then I tried the following:

gulp.task('sass', function () {
    return sass(['public/_sources/sass/*.scss',
             'public/_sources/sass/layouts/*.scss',
             'public/_sources/sass/modules/*.scss',
             'public/_sources/sass/vendors/*.scss'], { style: 'compressed' })
    // return sass('public/_sources/sass/**/*.scss', { style: 'compressed' })
    .pipe(sourcemaps.init())
    .pipe(concat('bitage_public.css'))
    .pipe(sourcemaps.write('./maps'))
    .pipe(gulp.dest('public/_assets/css'))
    .pipe(livereload());
});

But still I'm getting Errno::ENOENT: No such file or directory and it lists all the dirs I put into that array.

How do you compile SASS in multiple directories with gulp?

SASS source folder structure:

_sources
    layouts
        ...scss
    modules
        ...scss
    vendors
        ...scss
    main.scss

Answer

Leon Gaban picture Leon Gaban · Feb 15, 2015

Figured it out!

Well not 100%, still not sure why the multiple path array didn't work.

Anyways so I forgot that in my main web.scss file I already had multiple import statements setup:

@import "vendors/normalize";    // Normalize stylesheet
@import "modules/reset";        // Reset stylesheet
@import "modules/base";         // Load base files
@import "modules/defaults";     // Defaults
@import "modules/inputs";       // Inputs & Selects
@import "modules/buttons";      // Buttons
@import "modules/layout";       // Load Layouts
@import "modules/svg";          // Load SVG
@import "modules/queries";      // Media Queries

So I didn't actually need to try use Gulp the way I was trying, I just needed to target that 1 .scss file directly. So I did that here:

// Compile public SASS
gulp.task('sass', function () {
return sass('public/_sources/sass/bitage_web.scss', { style: 'compressed' })
    .pipe(sourcemaps.init())
    .pipe(sourcemaps.write('./maps'))
    .pipe(gulp.dest('public/_assets/css'))
    .pipe(livereload());
});

Now it works because it sees a specific file to target and compile