@@ -104,26 +104,21 @@ export async function viteBuild(opts: StaticBuildOptions) {
104
104
// For static builds, the SSR output won't be needed anymore after page generation.
105
105
// We keep track of the names here so we only remove these specific files when finished.
106
106
const ssrOutputChunkNames : string [ ] = [ ] ;
107
- const ssrOutputAssetNames : string [ ] = [ ] ;
108
107
for ( const output of ssrOutputs ) {
109
108
for ( const chunk of output . output ) {
110
109
if ( chunk . type === 'chunk' ) {
111
110
ssrOutputChunkNames . push ( chunk . fileName ) ;
112
111
}
113
- if ( chunk . type === 'asset' ) {
114
- ssrOutputAssetNames . push ( chunk . fileName ) ;
115
- }
116
112
}
117
113
}
118
114
119
- return { internals, ssrOutputChunkNames, ssrOutputAssetNames , contentFileNames } ;
115
+ return { internals, ssrOutputChunkNames, contentFileNames } ;
120
116
}
121
117
122
118
export async function staticBuild (
123
119
opts : StaticBuildOptions ,
124
120
internals : BuildInternals ,
125
121
ssrOutputChunkNames : string [ ] ,
126
- ssrOutputAssetNames : string [ ] ,
127
122
contentFileNames ?: string [ ] ,
128
123
) {
129
124
const { settings } = opts ;
@@ -136,7 +131,7 @@ export async function staticBuild(
136
131
settings . timer . start ( 'Server generate' ) ;
137
132
await generatePages ( opts , internals ) ;
138
133
await cleanStaticOutput ( opts , internals ) ;
139
- await ssrMoveAssets ( opts , ssrOutputAssetNames ) ;
134
+ await ssrMoveAssets ( opts ) ;
140
135
settings . timer . end ( 'Server generate' ) ;
141
136
}
142
137
}
@@ -417,21 +412,28 @@ export async function copyFiles(fromFolder: URL, toFolder: URL, includeDotfiles
417
412
) ;
418
413
}
419
414
420
- async function ssrMoveAssets ( opts : StaticBuildOptions , ssrOutputAssetNames : string [ ] ) {
415
+ async function ssrMoveAssets ( opts : StaticBuildOptions ) {
421
416
opts . logger . info ( 'build' , 'Rearranging server assets...' ) ;
422
417
const serverRoot =
423
418
opts . settings . buildOutput === 'static'
424
419
? opts . settings . config . build . client
425
420
: opts . settings . config . build . server ;
426
421
const clientRoot = opts . settings . config . build . client ;
427
- if ( ssrOutputAssetNames . length > 0 ) {
422
+ const assets = opts . settings . config . build . assets ;
423
+ const serverAssets = new URL ( `./${ assets } /` , appendForwardSlash ( serverRoot . toString ( ) ) ) ;
424
+ const clientAssets = new URL ( `./${ assets } /` , appendForwardSlash ( clientRoot . toString ( ) ) ) ;
425
+ const files = await glob ( `**/*` , {
426
+ cwd : fileURLToPath ( serverAssets ) ,
427
+ } ) ;
428
+
429
+ if ( files . length > 0 ) {
428
430
await Promise . all (
429
- ssrOutputAssetNames . map ( async function moveAsset ( filename ) {
430
- const currentUrl = new URL ( filename , appendForwardSlash ( serverRoot . toString ( ) ) ) ;
431
- const clientUrl = new URL ( filename , appendForwardSlash ( clientRoot . toString ( ) ) ) ;
431
+ files . map ( async function moveAsset ( filename ) {
432
+ const currentUrl = new URL ( filename , appendForwardSlash ( serverAssets . toString ( ) ) ) ;
433
+ const clientUrl = new URL ( filename , appendForwardSlash ( clientAssets . toString ( ) ) ) ;
432
434
const dir = new URL ( path . parse ( clientUrl . href ) . dir ) ;
433
435
// It can't find this file because the user defines a custom path
434
- // that includes the folder paths in `assetFileNames`
436
+ // that includes the folder paths in `assetFileNames
435
437
if ( ! fs . existsSync ( dir ) ) await fs . promises . mkdir ( dir , { recursive : true } ) ;
436
438
return fs . promises . rename ( currentUrl , clientUrl ) ;
437
439
} ) ,
0 commit comments