Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save megclaypool/3cb712a59d3e3460ba7e42f074c9b328 to your computer and use it in GitHub Desktop.
Save megclaypool/3cb712a59d3e3460ba7e42f074c9b328 to your computer and use it in GitHub Desktop.

Here's a gulp function that hops through the directory structure and compiles css files in the same directory as the corresponding scss file. It’s as simple as our current gulp routine, so we don’t have to abandon scss to use Single Directory Components unless we want to for other reasons 

/* This will compile individual css files in the same directory as the corresponding scss file */
function sdcscss() {
  return gulp
    .src("./assets/styles/**/*.scss", {
      base: "./assets/styles/",
    })
    .pipe(sassGlob({}))
    .pipe(sourcemaps.init())
    .pipe(sass({}).on("error", sass.logError))
    .pipe(sourcemaps.write("./"))
    .pipe(gulp.dest("./assets/styles/"));
}

We just have to be aware that any scss files whose names start with an underscore won’t be included, so underscores are only for files we’re globbing in inside an scss file. (edited) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment