diff --git a/.changeset/gold-wolves-fix.md b/.changeset/gold-wolves-fix.md new file mode 100644 index 000000000000..3e4484402684 --- /dev/null +++ b/.changeset/gold-wolves-fix.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +fix: reusing `kit.base.path` default in different phases diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index 7d6cf2a9589f..a401e3afd0ff 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -791,6 +791,8 @@ async function kit({ svelte_config }) { /** @type {import('vite').UserConfig} */ let new_config; + const kit_paths_base = kit.paths.base || '/'; + if (is_build) { const ssr = /** @type {boolean} */ (config.build?.ssr); const prefix = `${kit.appDir}/immutable`; @@ -872,7 +874,7 @@ async function kit({ svelte_config }) { // That's larger and takes longer to run and also causes an HTML diff between SSR and client // causing us to do a more expensive hydration check. const client_base = - kit.paths.relative !== false || kit.paths.assets ? './' : kit.paths.base || '/'; + kit.paths.relative !== false || kit.paths.assets ? './' : kit_paths_base; const inline = !ssr && svelte_config.kit.output.bundleStrategy === 'inline'; const split = ssr || svelte_config.kit.output.bundleStrategy === 'split'; @@ -931,7 +933,7 @@ async function kit({ svelte_config }) { } else { new_config = { appType: 'custom', - base: kit.paths.base, + base: kit_paths_base, build: { rollupOptions: { // Vite dependency crawler needs an explicit JS entry point