Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can the SASS minifier remove duplicate styles?

Tags:

I know that the css rules are fairly complex; however, couldn't the following css be fairly simply reduced in a number of ways by the optimizer? And if so, is there an option for it in the rails-sass gem?

span {     background: red;     color: green; }  .test2 {     background: red;     color: green; }  span {     background: green;     color: inherit; }  .test2 {     background: inherit !important;     color: inherit;     color: inherit;     color: inherit; } 

Additional Context:

To help clarify, I would propose the following as well...

Source:

span {     background: red; } span {     background: orange;     color: green; } span {     background: yellow; } span {     background: blue;     color: green; } 

And, I would want a compiler to generate the following:

span {     background: blue;     color: green; } 

I know there are redundant styles, but this happens many times when continually revising stylesheets, and I want to eliminate the dead code.

like image 354
Marshall Anschutz Avatar asked Jun 22 '12 17:06

Marshall Anschutz


1 Answers

I think that I may have found a way to at least find the duplicate styles in both css and sass/less templates:

The open source csscss gem http://zmoazeni.github.io/csscss/

It appears to be able to detect duplicates, although I am having to monkey patch around the bootstrap-sass gem's css not being in the same folder as my css assets.

From the documentation, you can run:

$ csscss -v path/to/styles.css 

or

$ csscss -v path/to/styles.css.scss 
like image 149
Marshall Anschutz Avatar answered Oct 22 '22 12:10

Marshall Anschutz