Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile SASS files in different directories using Gulp?

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
like image 683
Leon Gaban Avatar asked Feb 14 '15 22:02

Leon Gaban


2 Answers

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

like image 188
Leon Gaban Avatar answered Sep 21 '22 18:09

Leon Gaban


I was having trouble using '*.scss' too

In the git documentation (https://github.com/sindresorhus/gulp-ruby-sass) they use this sintax:

gulp.task('sass', function(){
   return sass('public/_sources/sass/',
   { style: 'compressed'})
.pipe(sourcemaps.init())
});

I tested it and it works, it compiles all the files within the folder.

Just in case someone has the same problem

like image 38
Raphael Isidro Avatar answered Sep 19 '22 18:09

Raphael Isidro