-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Optimize generated CSS output #14873
Conversation
Hard to tell from just the diff — is this change applied just to production builds or to dev and production? Also any chance you have benchmarked it on a realistic codebase? That would help to know if we should only do this in production or if it's fine to do it all the time. |
It's always applied whenever we use Lightning CSS. For example in the CLI we don't use But if you do use
|
07f617d
to
dbf77e5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea why the postcss snapshot now has three -webkit-text-decoration: inherit;
on the a
tag lol
I think this makes sense and I'd rather pay a small compile time fee of a few ms instead of expensive egress charges because the CSS can be more optimized 😅 We should explain with an example why we do this, though. transform(transform(foo))
looks like a typo otherwise 😄
|
||
// Running Lightning CSS twice to ensure that adjacent rules are merged after | ||
// nesting is applied. This creates a more optimized output. | ||
return optimize(optimize(Buffer.from(input))).toString() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we can get away with running optimize
just once if lightningcss
is configured as the CSS processor... It might have a different config so probably not 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's tricky. Our config sets Safari to a version that doesn't understand nesting yet.
One suggestion that Devon had was to put @media
queries on the outside instead of nested to do the merging, but the current change is a bit easier especially once Lightning CSS can handle this natively.
This will improve the output because Lightning CSS will first merge adjacent rules, then flatten the nesting. After that it does not try to merge adjacent rules anymore.
Co-authored-by: Philipp Spiess <hello@philippspiess.com>
717b7a8
to
774290e
Compare
This PR improves the generated CSS by running it through Lightning CSS twice.Right now Lightning CSS merges adjacent at-rules and at the end flattens the nesting. This means that after the nesting is flattened, the at-rules that are adjacent and could be merged together will not be merged.
This PR improves our output by running Lightning CSS twice on the generated CSS which will make sure to merge adjacent at-rules after the nesting is flattened.
Note: in the diff output you'll notice that some properties are duplicated. These need some fixes in Lightning CSS itself but they don't break anything for us right now.
Related PR in Lightning CSS for the double
-webkit-backdrop-filter
can be found here: parcel-bundler/lightningcss#850