Avoid Grunt cssmin task to remove duplicate entries

不打扰是莪最后的温柔 提交于 2020-01-13 03:12:11

问题


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

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

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?


回答1:


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.

One of the parameters available is;

advanced - set to false to disable advanced optimizations - selector & property merging, reduction, etc.

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.

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



来源:https://stackoverflow.com/questions/26279789/avoid-grunt-cssmin-task-to-remove-duplicate-entries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!