@@ -111,12 +111,15 @@ export function CssCodeSplitPlugin(
111111
112112 // Build an index of normalized chunk names for faster lookup
113113 const chunkNameIndex = new Map < string , string [ ] > ( )
114+ const chunkFileNamesByBaseName = new Map < string , string > ( )
114115 for ( const chunkFileName of chunkCSSMap . keys ( ) ) {
115116 const chunkBaseName = normalizeChunkFileName ( chunkFileName )
116117 if ( ! chunkNameIndex . has ( chunkBaseName ) ) {
117118 chunkNameIndex . set ( chunkBaseName , [ ] )
118119 }
119120 chunkNameIndex . get ( chunkBaseName ) ! . push ( chunkFileName )
121+ // Store mapping from chunk file name to base name for prefix matching
122+ chunkFileNamesByBaseName . set ( chunkFileName , chunkBaseName )
120123 }
121124
122125 // Match CSS assets to chunks by comparing base names
@@ -130,11 +133,22 @@ export function CssCodeSplitPlugin(
130133 break
131134 }
132135 } else {
133- // Fallback: check for prefix match
134- for ( const [ chunkFileName ] of chunkCSSMap ) {
135- if ( chunkFileName . startsWith ( `${ cssBaseName } -` ) ) {
136- chunkCSSMap . get ( chunkFileName ) ?. push ( cssFileName )
137- break
136+ // Fallback: check for prefix match by examining the base name index
137+ let found = false
138+ for ( const [ baseName , chunkFileNames ] of chunkNameIndex ) {
139+ // Check if CSS file name could be a variant (e.g., with hash)
140+ if (
141+ baseName . startsWith ( cssBaseName ) ||
142+ cssBaseName . startsWith ( baseName )
143+ ) {
144+ for ( const chunkFileName of chunkFileNames ) {
145+ if ( chunkFileName . startsWith ( `${ cssBaseName } -` ) ) {
146+ chunkCSSMap . get ( chunkFileName ) ?. push ( cssFileName )
147+ found = true
148+ break
149+ }
150+ }
151+ if ( found ) break
138152 }
139153 }
140154 }
0 commit comments