From ffbdcdb09afe1fa655601b446d724fa9a7b7f282 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 26 Jan 2023 05:12:07 -0500 Subject: [PATCH] fix: emit assets from SSR build (#11430) --- packages/vite/src/node/build.ts | 7 +++++++ packages/vite/src/node/plugins/asset.ts | 6 +++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/vite/src/node/build.ts b/packages/vite/src/node/build.ts index bbc2f86f8be349..8cdf5b37d7cc17 100644 --- a/packages/vite/src/node/build.ts +++ b/packages/vite/src/node/build.ts @@ -208,6 +208,12 @@ export interface BuildOptions { * directives in production. */ ssrManifest?: boolean | string + /** + * Emit assets during SSR. + * @experimental + * @default false + */ + ssrEmitAssets?: boolean /** * Set to false to disable reporting compressed chunk sizes. * Can slightly improve build speed. @@ -324,6 +330,7 @@ export function resolveBuildOptions( lib: false, ssr: false, ssrManifest: false, + ssrEmitAssets: false, reportCompressedSize: true, chunkSizeWarningLimit: 500, watch: null, diff --git a/packages/vite/src/node/plugins/asset.ts b/packages/vite/src/node/plugins/asset.ts index 43f7880931bb2a..dd73a9e1cd23f5 100644 --- a/packages/vite/src/node/plugins/asset.ts +++ b/packages/vite/src/node/plugins/asset.ts @@ -187,7 +187,11 @@ export function assetPlugin(config: ResolvedConfig): Plugin { generateBundle(_, bundle) { // do not emit assets for SSR build - if (config.command === 'build' && config.build.ssr) { + if ( + config.command === 'build' && + config.build.ssr && + !config.build.ssrEmitAssets + ) { for (const file in bundle) { if ( bundle[file].type === 'asset' &&