diff --git a/.changeset/chilled-drinks-itch.md b/.changeset/chilled-drinks-itch.md new file mode 100644 index 000000000000..d08fbf48603b --- /dev/null +++ b/.changeset/chilled-drinks-itch.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: remove unused SSR CSS assets diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 94f242a1e468..ff61a63af05a 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -720,10 +720,20 @@ function kit({ svelte_config }) { }) ); - copy( - `${out}/server/${kit.appDir}/immutable/assets`, - `${out}/client/${kit.appDir}/immutable/assets` - ); + // don't copy unused CSS generated by Vite's build.ssrEmitAssets option + const server_css = Object.values(server_manifest) + .filter((entry) => entry.css) + .map((entry) => entry.css) + .flat(); + + const assets_path = `${kit.appDir}/immutable/assets`; + + copy(`${out}/server/${assets_path}`, `${out}/client/${assets_path}`, { + filter: (basename) => { + const filepath = `${assets_path}/${basename}`; + return !server_css.includes(filepath); + } + }); /** @type {import('vite').Manifest} */ const client_manifest = JSON.parse(read(`${out}/client/${vite_config.build.manifest}`));