Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid copying unused SSR stylesheets to client assets #13069

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twelve-gifts-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: avoid copying SSR stylesheets to client assets
21 changes: 17 additions & 4 deletions packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,10 +815,23 @@ async function kit({ svelte_config }) {
})
);

copy(
`${out}/server/${kit.appDir}/immutable/assets`,
`${out}/client/${kit.appDir}/immutable/assets`
);
// we do not want to copy the unused server stylesheets generated by
// Vite's `build.ssrEmitAssets` option
/** @type {string[]} */
const ssr_stylesheets = [];
for (const key in server_manifest) {
const stylesheets = server_manifest[key].css;
if (stylesheets) {
ssr_stylesheets.push(...stylesheets);
}
}
const ssr_stylesheets_set = new Set(ssr_stylesheets);

const assets_path = `${kit.appDir}/immutable/assets`;

copy(`${out}/server/${assets_path}`, `${out}/client/${assets_path}`, {
filter: (basename) => !ssr_stylesheets_set.has(`${assets_path}/${basename}`)
});

/** @type {import('vite').Manifest} */
const client_manifest = JSON.parse(read(`${out}/client/${vite_config.build.manifest}`));
Expand Down
Loading