Skip to content

fix(css): resolve cssMinify from the environment config - #23243

Open
ValentinYoushkevich wants to merge 1 commit into
vitejs:mainfrom
ValentinYoushkevich:fix/css-minify-per-environment
Open

fix(css): resolve cssMinify from the environment config#23243
ValentinYoushkevich wants to merge 1 commit into
vitejs:mainfrom
ValentinYoushkevich:fix/css-minify-per-environment

Conversation

@ValentinYoushkevich

Copy link
Copy Markdown

Description

cssPostPlugin captures the root ResolvedConfig at plugin creation time and reads build.cssMinify from it. With builder.sharedPlugins: true a single plugin instance is reused across every environment, so a per-environment build.cssMinify was ignored and the root value was applied everywhere — the config in #20789 produces minified CSS for both the client and the ssr build.

This reads the option from this.environment.config instead, which is what the surrounding code in the same plugin already does for build.cssCodeSplit, build.emitAssets and build.chunkImportMap. compileLightningCSS resolves it per environment too, so this only aligns the remaining call sites.

Changed call sites, all in cssPostPlugin:

  • the ?inline branch in transform
  • finalizeCss for __VITE_CSS_URL__ emit tasks
  • finalizeCss for code-split chunk CSS
  • finalizeCss for inlined chunk CSS
  • finalizeCss for the extracted single stylesheet

Since minifyCSS receives the same config object, build.cssTarget, css.lightningcss and esbuild options used during minification now resolve per environment as well.

fixes #20789

Tests

Added cssMinify per environment with shared plugins next to the existing minify per environment and chunkImportMap per environment with shared plugins tests, using a new fixtures/shared-plugins/css-minify fixture. It builds two client-consumer environments with sharedPlugins: true — one with cssMinify: false, one with the default — and asserts the first emits unminified CSS while the second stays minified.

Without the fix the test fails with expected '.foo{color:red}.bar{color:#00f}' to contain '\n'.

`cssPostPlugin` captured the root resolved config at plugin creation and
read `build.cssMinify` from it. With `builder.sharedPlugins: true` a single
plugin instance is reused across environments, so a per-environment
`build.cssMinify` was ignored and the root value applied everywhere.

Read the option from `this.environment.config` instead, matching how the
surrounding code already resolves `cssCodeSplit` and `chunkImportMap`.
@ValentinYoushkevich
ValentinYoushkevich force-pushed the fix/css-minify-per-environment branch from acf2f80 to fbcb5a8 Compare August 12, 2026 11:09
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.

per environment cssMinify: false doesn't work when sharedPlugins: true

1 participant