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