Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(merge-rules): merge at-rules #722

Merged

Conversation

clshortfuse
Copy link
Contributor

No description provided.

@clshortfuse
Copy link
Contributor Author

@evilebottnawi I'm going to need some direction as to how to handle the integration tests failures.

@alexander-akait
Copy link
Member

@clshortfuse we have command in package.json to update snapshots

@alexander-akait
Copy link
Member

Can you describe above before/after for other developers

@coveralls
Copy link

coveralls commented Mar 20, 2019

Coverage Status

Coverage decreased (-0.1%) to 99.004% when pulling b61cbcc on clshortfuse:feat/mergerules-mergeatrules into 863cf2b on cssnano:master.

@clshortfuse
Copy link
Contributor Author

With the previous fix to sameParent, we can now check to see if adjacent rules' parents share the exact same name and parameters. If they do, then one set of rules can be merged into the previous parent's rules. A couple of the frameworks (numerous in bootstrap) used for integrations tests have redundant media query declarations. We can merge them safely if they are adjacent.

For example, given the follow set of rules:

@media (width:40px){ .red{color:red} }
@media (width:40px){ .green{color:green} }
@media (width:40px){ .blue{color:blue} }
@supports (--var:var){ .white{color:white} }
@supports (--var:var){ .black{color:black} }

The three identically matched @media rules will be all folded into the same parent (the first rule). The last @support rule will be folded into its previous rule.

The result would be:

@media (width:40px){.red{color:red}.green{color:green}.blue{color:blue}}
@media (width:40px){}
@media (width:40px){}
@supports (--var:var){@media (width:40px){.white{color:white}.black{color:black}}}
@supports (--var:var){@media (width:40px){}}

The empty nodes can then be removed by anther plugin, like postcss-discard-empty. Because some media queries can be rather long, this can reduce a bit off some frameworks (though this depends on how much redundancy was present). For example, bootstrap 3.4.0 is reduced from 120,549bytes to 120,007

@alexander-akait
Copy link
Member

Thanks for clarify. need rebase

@clshortfuse
Copy link
Contributor Author

@evilebottnawi rebased

@alexander-akait alexander-akait merged commit 8d4610a into cssnano:master Mar 21, 2019
@alexander-akait
Copy link
Member

Good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants