Using Gulp to Compile Sass and minify vendor css

前端 未结 3 1209
慢半拍i
慢半拍i 2021-01-31 08:26

Getting to grips with Gulp and have a question.

So I have a gulp CSS task like the below which works just fine:

var sassDir = \'app/scss\';
var targetCss         


        
3条回答
  •  一向
    一向 (楼主)
    2021-01-31 08:57

    gulp-sass will meet your request. Pls let me show you how to compile Sass files and minify (or compress) compiled css files:

    • install gulp-sass from here
    • in you project's gulpfile.js, add following code:

    Note: outputStyle in gulp-sass has four options: nested, expanded, compact, compressed

    It really works, I have used it in my project. Hope it helps.

    var gulp = require('gulp');
    var sass = require('gulp-sass');
    
    //sass
    gulp.task('sass', function () {
        gulp.src(['yourCSSFolder/*.scss', 'yourCSSFolder/**/*.scss'])
            .pipe(sass({outputStyle: 'compressed'}))
            .pipe(gulp.dest('yourCSSFolder/'));
    });
    
    // Default task
    gulp.task('default', function () {
        gulp.start('sass');
    });
    

    For reminder the readme

提交回复
热议问题