How to use cssnano as the final CSS minifier with injectStyles: true while keeping Lightning CSS prefixing/transforms?
#7225
Unanswered
zalishchuk
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am using Rsbuild and I have a case where I must keep
output.injectStyles: true(so CSS is injected into JS, not emitted as separate.cssfiles).Trying to understand the best/supported way to do this:
cssnanoas the final CSS minifier@rsbuild/plugin-css-minimizerseems to work at the CSS asset minimizer stage.With
output.injectStyles: true, there are no emitted CSS assets, so this plugin does not appear to be the right tool for this case.I tried using
cssnanoin PostCSS, while keepinglightningcss-loaderenabled and disabling its minification (minify: false).In that setup, Lightning CSS still runs after PostCSS (loader order), and it reserializes the CSS. In practice, this reintroduces formatting/newlines/whitespace and cancels out cssnano's minified formatting.
I tested this on my codebase and saw:
postcss (autoprefixer + cssnano)with Lightning disabled: compact/minified embedded CSS stringspostcss (autoprefixer + cssnano)+ Lightning loader (minify: false): multiline formatted CSS strings added back into the JS bundle, and bundle size increasedSo
cssnanois not the final serializer if Lightning loader is still enabled afterward.Is there a supported way in Rsbuild to keep Lightning CSS prefixing/transforms but still make
cssnanothe final CSS minifier/serializer whenoutput.injectStyles: true?I am investigating this because I want predictable final minification behavior, and I am cautious about optimizer rewrites in some CSS cases.
In particular, Lightning CSS can rewrite
translate3d(0, 0, 0)totranslate(0, 0), which is a bit off for my use case because it can affect compositing behavior (for example in Safari).One reason I am cautious about Lightning CSS minification right now is this issue/PR context:
I do not like that (at least from what I can see in Lightning CSS right now), I cannot easily configure Lightning CSS minifier behavior in a granular way to disable specific optimizations/rewrites that I consider risky for my project.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions