简体   繁体   中英

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.

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/'));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM