From 3d851ec09efae738ae737fbe4209106e874df490 Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Wed, 6 Sep 2023 01:40:55 +0800 Subject: [PATCH 1/4] remove server css files before copying --- packages/kit/src/exports/vite/index.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 94f242a1e468..6473588e5e37 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -720,6 +720,13 @@ function kit({ svelte_config }) { }) ); + // remove unused CSS files generated by vite's `build.ssrEmitAssets` option + for (const key in server_manifest) { + server_manifest[key].css?.forEach((filepath) => { + fs.unlinkSync(`${out}/server/${filepath}`); + }); + } + copy( `${out}/server/${kit.appDir}/immutable/assets`, `${out}/client/${kit.appDir}/immutable/assets` From 052fd5a6aff8ae26a1d9d82d19436f5b785c0769 Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Wed, 6 Sep 2023 02:45:21 +0800 Subject: [PATCH 2/4] changeset --- .changeset/chilled-drinks-itch.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/chilled-drinks-itch.md 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 From 95d772bfdab40825443000e3d6a9de0826ba36b7 Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Wed, 6 Sep 2023 03:19:51 +0800 Subject: [PATCH 3/4] prevent copying instead --- packages/kit/src/exports/vite/index.js | 27 ++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 6473588e5e37..e755b3781df7 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -720,18 +720,6 @@ function kit({ svelte_config }) { }) ); - // remove unused CSS files generated by vite's `build.ssrEmitAssets` option - for (const key in server_manifest) { - server_manifest[key].css?.forEach((filepath) => { - fs.unlinkSync(`${out}/server/${filepath}`); - }); - } - - copy( - `${out}/server/${kit.appDir}/immutable/assets`, - `${out}/client/${kit.appDir}/immutable/assets` - ); - /** @type {import('vite').Manifest} */ const client_manifest = JSON.parse(read(`${out}/client/${vite_config.build.manifest}`)); @@ -785,6 +773,21 @@ function kit({ svelte_config }) { })};\n` ); + // do not copy 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); + } + }); + if (service_worker_entry_file) { if (kit.paths.assets) { throw new Error('Cannot use service worker alongside config.kit.paths.assets'); From 104f19c35696b81a03c8e187530555cd14724fe8 Mon Sep 17 00:00:00 2001 From: Tee Ming Date: Wed, 6 Sep 2023 03:25:29 +0800 Subject: [PATCH 4/4] code placement --- packages/kit/src/exports/vite/index.js | 30 +++++++++++++------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index e755b3781df7..ff61a63af05a 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -720,6 +720,21 @@ function kit({ svelte_config }) { }) ); + // 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}`)); @@ -773,21 +788,6 @@ function kit({ svelte_config }) { })};\n` ); - // do not copy 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); - } - }); - if (service_worker_entry_file) { if (kit.paths.assets) { throw new Error('Cannot use service worker alongside config.kit.paths.assets');