think123 think123 - 26 days ago 21
Sass (Sass) Question

Gulp task to copy over all files in a directory, compile all SCSS files, leave others untouched?

I have a bunch of files inside an

scss
directory:

scss/
file.scss
anotherfile.scss
image.jpeg
dir/
other.ttf


I want
gulp
to compile this to:

css/
file.css
anotherfile.css
image.jpeg
dir/
other.ttf


Currently it compiles all
.css
files, but it doesn't copy over any of the other files.

This is what I currently have;

const path2 = require('path');
...
gulp.task('sass', function() {
gulp.src("./scss/*.scss")
.pipe(sass({outputStyle: 'compressed'}))
.on('error', onError)
.pipe(rename (function (path) {
path.dirname = path.dirname.replace(path2.sep + "scss", path2.sep + "css");
path.extname = ".css";
}))
.pipe(gulp.dest('./'));
});


How can I do this?

Thanks.

Answer
gulp.task('sass', function() {
  gulp.src("scss/*.scss")
    .pipe(sass({outputStyle: 'compressed'}))
    .on('error', onError)
    .pipe(gulp.dest('css/'));
  // copy everything except *.scss & *.sass
  gulp.src([
    "scss/**/*",
    "!scss/**/*.{sass,scss}"
    ])
    .pipe(gulp.dest('css/'));
});