CSS缩小和重命名与gulp [英] CSS minify and rename with gulp

查看:171
本文介绍了CSS缩小和重命名与gulp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个变量,例如

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

我想要gulp为我做的是 minify 文件,然后重命名

What I want the gulp to do for me is to minify the files and then rename for me.

但是任务目前写为档案)

But the tasks is currently written as (for one file)

gulp.task('minify', function () {
    gulp.src('foo.css')
        .pipe(minify({keepBreaks: true}))
        .pipe(concat('foo.min.css'))
        .pipe(gulp.dest('./'))
});

如何重写,使其适用于我的变量 files

How to rewrite so it work with my variable files defined above?

推荐答案

您应该能够使用Glob选择src所需的任何文件,在一个对象,这应该简化你的任务。此外,如果你想将css文件缩小到单独的文件,你不需要将它们连接起来。

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() {

});

这篇关于CSS缩小和重命名与gulp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆