@@ -32,13 +32,50 @@ export function manifestPlugin(config: ResolvedConfig): Plugin {
32
32
return perEnvironmentPlugin ( 'native:manifest' , ( environment ) => {
33
33
if ( ! environment . config . build . manifest ) return false
34
34
35
- return nativeManifestPlugin ( {
36
- root : environment . config . root ,
37
- outPath :
38
- environment . config . build . manifest === true
39
- ? '.vite/manifest.json'
40
- : environment . config . build . manifest ,
41
- } )
35
+ const root = environment . config . root
36
+ const outPath =
37
+ environment . config . build . manifest === true
38
+ ? '.vite/manifest.json'
39
+ : environment . config . build . manifest
40
+
41
+ function getChunkName ( chunk : OutputChunk ) {
42
+ return (
43
+ getChunkOriginalFileName ( chunk , root , false ) ??
44
+ `_${ path . basename ( chunk . fileName ) } `
45
+ )
46
+ }
47
+
48
+ return [
49
+ nativeManifestPlugin ( { root, outPath } ) ,
50
+ {
51
+ name : 'native:manifest-compatible' ,
52
+ generateBundle ( _ , bundle ) {
53
+ const asset = bundle [ outPath ]
54
+ if ( asset . type === 'asset' ) {
55
+ let manifest : Manifest | undefined
56
+ for ( const chunk of Object . values ( bundle ) ) {
57
+ if ( chunk . type !== 'chunk' ) continue
58
+ const importedCss = chunk . viteMetadata ?. importedCss
59
+ const importedAssets = chunk . viteMetadata ?. importedAssets
60
+ if ( ! importedCss ?. size && ! importedAssets ?. size ) continue
61
+ manifest ??= JSON . parse ( asset . source . toString ( ) ) as Manifest
62
+ const name = getChunkName ( chunk )
63
+ const item = manifest [ name ]
64
+ if ( ! item ) continue
65
+ if ( importedCss ?. size ) {
66
+ item . css = [ ...importedCss ]
67
+ }
68
+ if ( importedAssets ?. size ) {
69
+ item . assets = [ ...importedAssets ]
70
+ }
71
+ }
72
+ if ( manifest ) {
73
+ asset . source = JSON . stringify ( manifest )
74
+ }
75
+ }
76
+ } ,
77
+ } ,
78
+ ]
42
79
} )
43
80
}
44
81
0 commit comments