简体   繁体   中英

Minify CSS with Gulp via .pipe

Is it possible to use a plugin such as clean-css, so the CSS is minified upon every page refresh/save..? How would I chain it via pipe so it reaches the dist folder minified? Thanks for any help!

This is the current code:

gulp.task('styles', function(){
    return gulp.src('css/style.css')
        .pipe(postcss([cssImport, mixins, cssvars, nested, hexrgba, autoprefixer]))
        .on('error', function(errorInfo){
            console.log(errorInfo.toString());
            this.emit('end');
        })
        //stylesheet destination folder
        .pipe(gulp.dest('dist/styles'));
});

You can use uglifycss:

uglifycss = require('gulp-uglifycss');

gulp.task('styles', function(){
    return gulp.src('css/style.css')
        .pipe(postcss([cssImport, mixins, cssvars, nested, hexrgba, autoprefixer]))
        .on('error', function(errorInfo){
            console.log(errorInfo.toString());
            this.emit('end');
        })
        .pipe(uglifycss({
            "maxLineLen": 80,
            "uglyComments": true
        }))
        //stylesheet destination folder
        .pipe(gulp.dest('dist/styles'));
});

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