Avoid the grunt cssmin task to remove duplicate entries

In my Gruntfile I am using the cssmin task (grunt-contrib-cssmin). Sort of:

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

The problem is this: styles.css is generated using a concat task that combines many .css files. In some files I have the same css selector (example: .panel a) Only the first selector is stored in the cssmin task, all the others are deleted. I assume this is the default behavior of the task. Is there a way to keep duplicate selectors?

+5
source share
1 answer

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

One of the available options:

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

You play with this option at http://refresh-sf.com/ . If you go to the "clean-css" tab under the text box, you can enable / disable advanced to see how it works.

Edit: issued in grunt-contrib-cssmin repository as a problem https://github.com/gruntjs/grunt-contrib-cssmin/issues/263

0
source

Source: https://habr.com/ru/post/1204332/


All Articles