CSS minify and rename with gulp

后端 未结 3 1063
走了就别回头了
走了就别回头了 2021-02-01 15:59

I\'ve a variable like

var files = {
    \'foo.css\': \'foo.min.css\',
    \'bar.css\': \'bar.min.css\',
};

What I want the gulp to do for me is

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-01 16:45

    You should be able to select any files you need for your src with a Glob rather than defining them in an object, which should simplify your task. Also, if you want the css files minified into separate files you shouldn't need to concat them.

    var gulp = require('gulp');
    var minify = require('gulp-minify-css');
    var rename = require('gulp-rename');
    
    gulp.task('minify', function () {
        gulp.src('./*.css')
            .pipe(minify({keepBreaks: true}))
            .pipe(rename({
                suffix: '.min'
            }))
            .pipe(gulp.dest('./'))
        ;
    });
    
    gulp.task('default', ['minify'], function() {
    
    });
    

提交回复
热议问题