rbtech / css-purge

A CSS tool written in Node JS as a command line app or library for the purging, burning, reducing, shortening, compressing, cleaning, trimming and formatting of duplicate, extra, excess or bloated CSS.
http://rbtech.github.io/css-purge
MIT License
125 stars 19 forks source link

Ordering is not preserved on selectors #31

Closed dinubs closed 5 years ago

dinubs commented 6 years ago

Hi, I'm really impressed with css-purge so far. Curious to know if there's an option to preserve the ordering of selectors to match the order they were written initially. Take the code below for example:

h1 {
  color: red;
}

h1, h2 {
  color: purple;
}

h1 {
  color: black;
}

I would expect it to output the following

h1, h2 {
  color: purple;
}

h1 {
  color: black;
}

but it actually output this:

$ css-purge -c "h1 { color: red; } h1, h2 { color: purple; } h1 { color: black; }"
h1{color:#000}h1,h2{color:purple}

As you can tell this will not result in the correct thing showing up, the h1 will be color: purple instead of the intended color: black.

(note: this example is incredibly scaled down from the actual problem existing in my codebase where we have +300kb of duplicated styles that we're trying to auto-deduplicate until we can solve the actual problem)

AndrewEQ commented 6 years ago

Ok, thanks for the feedback @dinubs, will have a look at it asap.

AndrewEQ commented 5 years ago

Sorted it out, test and lemme know if you still have an issue.