代码之家  ›  专栏  ›  技术社区  ›  DevJoe

通过Gulp via缩小CSS。管

  •  1
  • DevJoe  · 技术社区  · 8 年前

    是否可以使用诸如clean css之类的插件,以便在每次页面刷新/保存时缩小css。。?如何通过管道将其链接到缩小的dist文件夹?谢谢你的帮助!

    这是当前代码:

    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'));
    });
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   JS1    8 年前

    您可以使用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'));
    });