@@ -8,7 +8,7 @@ import type {
8
8
import type { Plugin } from '../plugin'
9
9
import { normalizePath , sortObjectKeys } from '../utils'
10
10
import { usePerEnvironmentState } from '../environment'
11
- import { generatedAssetsMap } from './asset'
11
+ import { cssEntriesMap } from './asset'
12
12
13
13
const endsWithJSRE = / \. [ c m ] ? j s $ /
14
14
@@ -127,18 +127,15 @@ export function manifestPlugin(): Plugin {
127
127
return manifestChunk
128
128
}
129
129
130
- const assets = generatedAssetsMap . get ( this . environment ) !
131
- const entryCssAssetFileNames = new Set ( )
132
- for ( const [ id , asset ] of assets . entries ( ) ) {
133
- if ( asset . isEntry ) {
134
- try {
135
- const fileName = this . getFileName ( id )
136
- entryCssAssetFileNames . add ( fileName )
137
- } catch {
138
- // The asset was generated as part of a different output option.
139
- // It was already handled during the previous run of this plugin.
140
- assets . delete ( id )
141
- }
130
+ const entryCssReferenceIds = cssEntriesMap . get ( this . environment ) !
131
+ const entryCssAssetFileNames = new Set ( entryCssReferenceIds )
132
+ for ( const id of entryCssReferenceIds ) {
133
+ try {
134
+ const fileName = this . getFileName ( id )
135
+ entryCssAssetFileNames . add ( fileName )
136
+ } catch {
137
+ // The asset was generated as part of a different output option.
138
+ // It was already handled during the previous run of this plugin.
142
139
}
143
140
}
144
141
@@ -148,28 +145,24 @@ export function manifestPlugin(): Plugin {
148
145
const chunk = bundle [ file ]
149
146
if ( chunk . type === 'chunk' ) {
150
147
manifest [ getChunkName ( chunk ) ] = createChunk ( chunk )
151
- } else if ( chunk . type === 'asset' && typeof chunk . name === 'string' ) {
148
+ } else if ( chunk . type === 'asset' && chunk . names . length > 0 ) {
152
149
// Add every unique asset to the manifest, keyed by its original name
153
- const src = chunk . originalFileName ?? chunk . name
150
+ const src =
151
+ chunk . originalFileNames . length > 0
152
+ ? chunk . originalFileNames [ 0 ]
153
+ : chunk . names [ 0 ]
154
154
const isEntry = entryCssAssetFileNames . has ( chunk . fileName )
155
155
const asset = createAsset ( chunk , src , isEntry )
156
156
157
157
// If JS chunk and asset chunk are both generated from the same source file,
158
158
// prioritize JS chunk as it contains more information
159
159
const file = manifest [ src ] ?. file
160
- if ( file && endsWithJSRE . test ( file ) ) continue
161
-
162
- manifest [ src ] = asset
163
- fileNameToAsset . set ( chunk . fileName , asset )
164
- }
165
- }
160
+ if ( ! ( file && endsWithJSRE . test ( file ) ) ) {
161
+ manifest [ src ] = asset
162
+ fileNameToAsset . set ( chunk . fileName , asset )
163
+ }
166
164
167
- // Add deduplicated assets to the manifest
168
- for ( const [ referenceId , { originalFileName } ] of assets . entries ( ) ) {
169
- if ( ! manifest [ originalFileName ] ) {
170
- const fileName = this . getFileName ( referenceId )
171
- const asset = fileNameToAsset . get ( fileName )
172
- if ( asset ) {
165
+ for ( const originalFileName of chunk . originalFileNames . slice ( 1 ) ) {
173
166
manifest [ originalFileName ] = asset
174
167
}
175
168
}
0 commit comments