-
-
Notifications
You must be signed in to change notification settings - Fork 57
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(styled-components): Implement minification #235
feat(styled-components): Implement minification #235
Conversation
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 think we should use swc_css
or lightningcss
for minification.
(I prefer lightningcss
, because turbopack is going to use it)
Lightningcss does not support line comments. swc_css supports line comments, but I doubt it works for all syntax styled-components supports. For example, swc_css might not be able to parse the following style into AST. const Box = styled.div`
animation: ${p => p.anim};
${p => p.type}: red;
${p => p.additionalRules};
${MyComponent} {
color: red;
}
`
// <Box animation="slidein 3s linear 1s" type="background-color" additionalRules="opacity: 0.1">foo</Box> So I think using lightningcss or swc_css would cause regression against the regex-based method used in babel-plugin-styled-components. |
Do you know what might be needed to make minification work with the |
Ah I just saw your other PR, looking forward to using that! Thank you. |
This implements
minify
option in styled-components plugin. The minification algorithm and unit tests are ported frombabel-plugin-styled-components
.Note that CSS code in helper functions (
keyframes
,css
, etc.) are currently not always processed. I think there is a bug inis_helper
function, so I'll fix it in another pull request later.fixes #143
cf. vercel/next.js#30802