@@ -202,15 +202,7 @@ export default function vitePluginRsc(
202202 clientReferenceMetaMap = sortObject ( clientReferenceMetaMap )
203203 serverResourcesMetaMap = sortObject ( serverResourcesMetaMap )
204204 await builder . build ( builder . environments . client ! )
205-
206- const assetsManifestCode = `export default ${ serializeValueWithRuntime (
207- buildAssetsManifest ,
208- ) } `
209- const manifestPath = path . join (
210- builder . environments ! . rsc ! . config . build ! . outDir ! ,
211- BUILD_ASSETS_MANIFEST_NAME ,
212- )
213- fs . writeFileSync ( manifestPath , assetsManifestCode )
205+ writeAssetsManifest ( [ 'rsc' ] )
214206 return
215207 }
216208
@@ -229,6 +221,22 @@ export default function vitePluginRsc(
229221 serverResourcesMetaMap = sortObject ( serverResourcesMetaMap )
230222 await builder . build ( builder . environments . client ! )
231223 await builder . build ( builder . environments . ssr ! )
224+ writeAssetsManifest ( [ 'ssr' , 'rsc' ] )
225+ }
226+
227+ function writeAssetsManifest ( environmentNames : string [ ] ) {
228+ // output client manifest to non-client build directly.
229+ // this makes server build to be self-contained and deploy-able for cloudflare.
230+ const assetsManifestCode = `export default ${ serializeValueWithRuntime (
231+ buildAssetsManifest ,
232+ ) } `
233+ for ( const name of environmentNames ) {
234+ const manifestPath = path . join (
235+ config . environments [ name ] ! . build . outDir ,
236+ BUILD_ASSETS_MANIFEST_NAME ,
237+ )
238+ fs . writeFileSync ( manifestPath , assetsManifestCode )
239+ }
232240 }
233241
234242 return [
@@ -752,24 +760,6 @@ export default function vitePluginRsc(
752760 }
753761 return
754762 } ,
755- writeBundle ( ) {
756- // TODO: move this to `buildApp`.
757- // note that we already do this in buildApp for no-ssr case.
758- if ( this . environment . name === 'ssr' ) {
759- // output client manifest to non-client build directly.
760- // this makes server build to be self-contained and deploy-able for cloudflare.
761- const assetsManifestCode = `export default ${ serializeValueWithRuntime (
762- buildAssetsManifest ,
763- ) } `
764- for ( const name of [ 'ssr' , 'rsc' ] ) {
765- const manifestPath = path . join (
766- config . environments [ name ] ! . build . outDir ,
767- BUILD_ASSETS_MANIFEST_NAME ,
768- )
769- fs . writeFileSync ( manifestPath , assetsManifestCode )
770- }
771- }
772- } ,
773763 } ,
774764 createVirtualPlugin ( 'vite-rsc/bootstrap-script-content' , function ( ) {
775765 assert ( this . environment . name !== 'client' )
0 commit comments