@@ -104,26 +104,21 @@ export async function viteBuild(opts: StaticBuildOptions) {
104104 // For static builds, the SSR output won't be needed anymore after page generation.
105105 // We keep track of the names here so we only remove these specific files when finished.
106106 const ssrOutputChunkNames : string [ ] = [ ] ;
107- const ssrOutputAssetNames : string [ ] = [ ] ;
108107 for ( const output of ssrOutputs ) {
109108 for ( const chunk of output . output ) {
110109 if ( chunk . type === 'chunk' ) {
111110 ssrOutputChunkNames . push ( chunk . fileName ) ;
112111 }
113- if ( chunk . type === 'asset' ) {
114- ssrOutputAssetNames . push ( chunk . fileName ) ;
115- }
116112 }
117113 }
118114
119- return { internals, ssrOutputChunkNames, ssrOutputAssetNames , contentFileNames } ;
115+ return { internals, ssrOutputChunkNames, contentFileNames } ;
120116}
121117
122118export async function staticBuild (
123119 opts : StaticBuildOptions ,
124120 internals : BuildInternals ,
125121 ssrOutputChunkNames : string [ ] ,
126- ssrOutputAssetNames : string [ ] ,
127122 contentFileNames ?: string [ ] ,
128123) {
129124 const { settings } = opts ;
@@ -136,7 +131,7 @@ export async function staticBuild(
136131 settings . timer . start ( 'Server generate' ) ;
137132 await generatePages ( opts , internals ) ;
138133 await cleanStaticOutput ( opts , internals ) ;
139- await ssrMoveAssets ( opts , ssrOutputAssetNames ) ;
134+ await ssrMoveAssets ( opts ) ;
140135 settings . timer . end ( 'Server generate' ) ;
141136 }
142137}
@@ -417,21 +412,28 @@ export async function copyFiles(fromFolder: URL, toFolder: URL, includeDotfiles
417412 ) ;
418413}
419414
420- async function ssrMoveAssets ( opts : StaticBuildOptions , ssrOutputAssetNames : string [ ] ) {
415+ async function ssrMoveAssets ( opts : StaticBuildOptions ) {
421416 opts . logger . info ( 'build' , 'Rearranging server assets...' ) ;
422417 const serverRoot =
423418 opts . settings . buildOutput === 'static'
424419 ? opts . settings . config . build . client
425420 : opts . settings . config . build . server ;
426421 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 ) {
428430 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 ( ) ) ) ;
432434 const dir = new URL ( path . parse ( clientUrl . href ) . dir ) ;
433435 // 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
435437 if ( ! fs . existsSync ( dir ) ) await fs . promises . mkdir ( dir , { recursive : true } ) ;
436438 return fs . promises . rename ( currentUrl , clientUrl ) ;
437439 } ) ,
0 commit comments