0

Is there a way to exclude a sass file when building? I have the following code:

function style() {
return gulp
    .src(['./src/scss/**/*.scss', '!./src/scss/styleguide/**'])
    .pipe(gulpif(isDevelopment, sourcemaps.init()))
    .pipe(sassGlob())
    .pipe(sass())
    .on("error", sass.logError)
    .pipe(postcss([autoprefixer(), cssnano()]))
    .pipe(gulpif(isDevelopment, sourcemaps.write()))
    .pipe(gulp.dest(paths.styles.dest))
    .pipe(gulpif(isDevelopment, browserSync.stream()));}

I would like to exclude everything in the styleguide folder. Any ideas?

nmsdvid
  • 2,832
  • 2
  • 21
  • 21

1 Answers1

0

Your code works for me. Use gulp-debug to check which files are being passed through to the stream.

const debug = require("gulp-debug");

function style() {
return gulp

    // try both ways to see the difference
    //.src(['./src/scss/**/*.scss'])
    .src(['./src/scss/**/*.scss', '!./src/scss/styleguide/**'])

    .pipe(debug());

    //.pipe(gulpif(isDevelopment, sourcemaps.init()))
    //.pipe(sassGlob())
    //.pipe(sass())
    //.on("error", sass.logError)
    //.pipe(postcss([autoprefixer(), cssnano()]))
    //.pipe(gulpif(isDevelopment, sourcemaps.write()))
    //.pipe(gulp.dest(paths.styles.dest))
    //.pipe(gulpif(isDevelopment, browserSync.stream()))
}

When I set up your folder structure using this code I see the styleguide folder files are not being passed through.

├── gulpfile.js
├── src
|  └── scss
|     ├── main.scss
|     └── styleguide
|        └── test1.scss
Mark
  • 143,421
  • 24
  • 428
  • 436
  • Good idea to use gulp-debug, the file is not showing up in the logs, but its still included in the main.css. For example, by adding background red to the body in the styleguide.scss, the styleguide.scss is not shown in the logs but the body is red. Maybe this could be a bug in 4.0.2 ? – nmsdvid Aug 31 '19 at 12:32
  • Are you importing it into main.scss? Then excluding it from the gulp.src won't prevent that. You would have to comment out the `import` line. – Mark Aug 31 '19 at 12:34
  • Yepp I was, by removing the import statement solved my problem. thanks your for your help. – nmsdvid Sep 01 '19 at 09:31