避免Grunt cssmin任务删除重复的条目 [英] Avoid Grunt cssmin task to remove duplicate entries

查看:168
本文介绍了避免Grunt cssmin任务删除重复的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Gruntfile我使用cssmin(grunt-contrib-cssmin)任务。像:

In my Gruntfile I'm using cssmin (grunt-contrib-cssmin) task. Something like:

cssmin: {
    css : {
        src: "dist/styles.css",
        dest: "dist/styles.min.css"
    }
}

问题是:styles.css是使用concat任务生成的,它连接了许多.css文件。在一些文件中,我有相同的CSS选择器(例如:.panel a)
只有第一个选择器保持cssmin任务,所有其他的删除。我猜这是任务的默认行为。有没有办法保留重复的选择器?

The problem is: styles.css is generated with a concat task that concatenates lots of .css files. In some of files I have the same css selector (example: .panel a) Only the first one selector is kept bu the cssmin task, all others are removed. I guess it's a default behaviour of the task. Is there a way to keep duplicated selectors?

推荐答案

Grunt cssmin对node.js模块clean-css有一个依赖。我建议在Grunt中使用 clean-css API选项 https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-api

Grunt cssmin has a dependency on node.js module clean-css. I would recommend to use clean-css API within Grunt with the options available https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-api.

可用的参数之一是:

advanced - 设置为false以禁用高级优化 - selector& ;属性合并,缩减等。

您可以在 http://refresh-sf.com/ 。如果您转到textarea下面的标签'clean-css',您可以启用/禁用高级以使其正常工作。

You play with this option on http://refresh-sf.com/. If you go to tab 'clean-css' below the textarea, you could enable/disable advanced to see it working.

编辑:在grunt-contrib-cssmin作为问题发出此问题 https: //github.com/gruntjs/grunt-contrib-cssmin/issues/263

Issued this at grunt-contrib-cssmin repo as an issue https://github.com/gruntjs/grunt-contrib-cssmin/issues/263

这篇关于避免Grunt cssmin任务删除重复的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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