fix(vite): inline release bundle css with minified sentinel, in import order - #11477
Merged
Merged
Conversation
…t order The release minifier prints the bundle-CSS sentinel as a template literal, which the quote-only regex missed, so JS-imported CSS was silently dropped. CSS assets are now also concatenated in chunk import order so vendor.css precedes the app's CSS, matching dev. Closes #11476
|
View your CI Pipeline Execution ↗ for commit c57cf2f
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Checklist
What is the current behavior?
In release builds, CSS imported from JS/TS or SFC
<style>blocks is inlined into the bundle bymainEntryPlugin'sgenerateBundle, which replaces a__NS_BUNDLE_CSS_AST__sentinel with the stylesheet AST. Two problems:generateBundleand prints the sentinel as a template literal (m(`__NS_BUNDLE_CSS_AST__`,`ns-bundle-css`)). The replacement regex only accepts'and", so it never matches and the stylesheet is silently dropped.vendor.css. Rules fromnode_modulesstylesheets then win equal-specificity ties against the app's overrides, unlike in dev.What is the new behavior?
The inlining logic moves to
helpers/bundle-css.ts:viteMetadata.importedCss), then its dynamic imports, then any unclaimed assets. This matches import order, as in dev.Verified with a release build (
vite build --mode production -- --env.ios) of an app importing anode_modulesstylesheet and then an app stylesheet. Before the fix, the sentinel was left inbundle.mjsand neither rule was present. After the fix,bundle CSS: 2 asset(s) … applied=true, no sentinel remains, and the vendor rule precedes the app rule in the inlined AST.Tests:
packages/vite/helpers/bundle-css.spec.tscovers the template-literal and quoted sentinels, import ordering (static before importer, dynamic after, unclaimed last), and keeping the assets when no chunk carries the sentinel.Closes #11476.