Gulp Sass Dependency Issue

gulp.task('districtSass', function() {

  var districtSchoolSass=null;
  if(config.districts.length) {
    config.districts.forEach(function(school) {
      districtSchoolSass = 'src/sass/districts/'+school+'.scss';
      if(!fs.existsSync(districtSchoolSass)) {
        fs.writeFileSync(districtSchoolSass, '@import "all";')
      }
      return gulp.src([districtSchoolSass,'src/sass/districts/_all.scss'])
      // .pipe(changed(themepath+'/districts/'+school+'/css', {extension: '.css'}))
      .pipe(sass({ style : config.sass_style}))
      .on("error", handleError)
      .pipe(autoprefixer({
        browsers: ['> 1%', 'last 4 versions', 'Firefox ESR', 'Opera 12.1'],
        cascade: false
      }))
      .pipe(gulp.dest('./dist/districts/'+school+'/css'))
      .pipe(gulp.dest(themepath+'/districts/'+school+'/css'))
      .pipe(browserSync.stream());
    });
  }

});

I have this sort of setup
/src/sass/districts/_all.scss
/src/sass/districts/school1.scss
//more schools

I’m trying to make it so if I save a school file, it only recompiles that one Sass file, but if I save _all, then every file gets recompiled. Right now every file gets recompiled no matter what, but if I uncomment that pipe(changed()) line, then it works EXCEPT for when I need to save _all; THEN it doesn’t compile anything / push to the dest()'s. Any ideas? I found merge-stream npm but it wasn’t working for me so I abandoned it.

Does anyone have some thoughts? Perhaps even just theoretical logic I can put in place?

Why are you trying to compile a partial directly? Perhaps something weird is going on there with the Sass compiler. Maybe not, but you shouldn’t be compiling partials by themselves. It defeats the purpose.

I have this sort of setup
/src/sass/districts/_all.scss
/src/sass/districts/school1.scss
//more schools

This looks backwards to me. Looks like it should be _school1.scss and all.scss.

Well school1.scss is going to compile into school1.css. Each school will generate its own CSS file (so if there are 8 schools, 8 CSS files).

_all.scss will have mixins and stuff that has color changes that apply to all schools. So each school will import “all” and each school will generate as its own stand-alone CSS file (there’s a school1.scss for school-specific Sass).

It’s not set up backwards :slight_smile: thank you though. Did I explain it adequately?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.