简体   繁体   中英

In Gulp how to prevent gulp-sass to minify css into 1 file

Is there a way to tell gulp-sass to process SASS files but still keep the source folder structure. We don't want them to be minified/concatenated into one main file. For example if I have:

src/
  components/
    _header.scss
    _sidebar.scss
    _card.scss

Can I tell it to process them into:

dist/
  components/
    header.css
    sidebar.css
    card.css

Gulpfile

gulp.task('styles:dist', () => {
  return gulp
    .src('./src/styles/**/*.+(scss|sass|css)', { base: './' })
    .pipe(
      sass({
        outputStyle: 'expanded',
      }).on('error', sass.logError)
    )
    .pipe(gulp.dest('./dist'));
});

Thanks in advance!

First install cleanCSS gulp plugin then run your task for convert scss or sass or less files to css then use css task for convert all css files to one minified and merge css file.

var cleanCSS = require('gulp-clean-css');

gulp.task('css', () => {
return gulp.src('./src/styles/**/*.css')
  .pipe(cleanCSS({
      compatibility: 'ie8',
      level: {
          1: {
              specialComments: 0,
          },
      },
  }))
  .pipe('./dist'))
});

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