@@ -26,11 +26,16 @@ import { extractAssetsAddQuery } from '../../shared/extractAssetsQuery.js'
26
26
type InputOption = Rollup . InputOption
27
27
import { createRequire } from 'module'
28
28
import { getClientEntryFilePath } from '../../shared/getClientEntryFilePath.js'
29
+ import fs from 'fs/promises'
30
+ import path from 'path'
29
31
// @ts -ignore Shimed by dist-cjs-fixup.js for CJS build.
30
32
const importMetaUrl : string = import . meta. url
31
33
const require_ = createRequire ( importMetaUrl )
32
34
35
+ const manifestTempFile = '_temp_manifest.json'
36
+
33
37
function buildConfig ( ) : Plugin {
38
+ let generateManifest : boolean
34
39
return {
35
40
name : 'vite-plugin-ssr:buildConfig' ,
36
41
apply : 'build' ,
@@ -51,13 +56,27 @@ function buildConfig(): Plugin {
51
56
}
52
57
} ,
53
58
config ( config ) {
59
+ generateManifest = ! viteIsSSR ( config )
54
60
return {
55
61
build : {
56
62
outDir : resolveOutDir ( config ) ,
57
- manifest : ! viteIsSSR ( config ) ,
63
+ manifest : generateManifest ? manifestTempFile : false ,
58
64
copyPublicDir : ! viteIsSSR ( config )
59
65
}
60
66
} satisfies UserConfig
67
+ } ,
68
+ async writeBundle ( options , bundle ) {
69
+ const manifestEntry = bundle [ manifestTempFile ]
70
+ if ( generateManifest ) {
71
+ assert ( manifestEntry )
72
+ const { dir } = options
73
+ assert ( dir )
74
+ const manifestFilePathOld = path . join ( dir , manifestEntry . fileName )
75
+ const manifestFilePathNew = path . join ( dir , '..' , 'manifest.json' )
76
+ await fs . rename ( manifestFilePathOld , manifestFilePathNew )
77
+ } else {
78
+ assert ( ! manifestEntry )
79
+ }
61
80
}
62
81
}
63
82
}
0 commit comments