🐛 Keep Svelte's browser runtime in the production bundle
The test setup for reactive reads set resolve.conditions for every mode. Outside tests the empty list replaced Vite's defaults, so Svelte resolved to its server build, where onMount is a no-op that the bundler drops. The layout then never resolved its sign-in gate and showed "Loading…" forever. The conditions are now only set for vitest.
This commit is contained in:
+4
-2
@@ -9,8 +9,10 @@ import { VitePWA } from 'vite-plugin-pwa';
|
|||||||
const buildId = Date.now().toString();
|
const buildId = Date.now().toString();
|
||||||
|
|
||||||
export default defineConfig(({ mode }) => ({
|
export default defineConfig(({ mode }) => ({
|
||||||
// Vitest resolves the `browser` export of Svelte, so effects re-run in tests like in the app.
|
// Vitest needs the `browser` export of Svelte so that effects re-run in tests like in the app.
|
||||||
resolve: { conditions: mode === 'test' ? ['browser'] : [] },
|
// Builds must not set `resolve.conditions`: an explicit list replaces Vite's defaults and
|
||||||
|
// resolves Svelte to its server build, where onMount is a no-op that gets tree-shaken away.
|
||||||
|
...(mode === 'test' ? { resolve: { conditions: ['browser'] } } : {}),
|
||||||
plugins: [
|
plugins: [
|
||||||
sveltekit(),
|
sveltekit(),
|
||||||
VitePWA({
|
VitePWA({
|
||||||
|
|||||||
Reference in New Issue
Block a user