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

ViteJS dev server bug workaround #200

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Expand Up @@ -181,7 +181,27 @@ In the browser we wait until all child `Route` components have registered with t

We therefore resort to picking the first matching `Route` that is registered on the server, so it is of utmost importance that you `sort your Route components from the most specific to the least specific if you are using SSR`.

## Vite JS Caveat

Vite JS's dev server pre bundles `svelte-routing` incorrectly, causing two copies of internal variables to exist and break the routing.
We need to add `optimizeDeps: {exclude: ["svelte-routing"]}` to `vite.config.js` to work around this.

Example `vite.config.js`:
```js
import { defineConfig } from "vite";
import svelte from "@sveltejs/vite-plugin-svelte";

// https://vitejs.dev/config/
export default defineConfig({
plugins: [svelte()],
optimizeDeps: {exclude: ["svelte-routing"]}
});
```

See https://github.com/vitejs/vite/issues/3155 for more information.

[npm]: https://img.shields.io/npm/v/svelte-routing.svg
[npm-url]: https://npmjs.com/package/svelte-routing
[example-folder-url]: https://github.com/EmilTholin/svelte-routing/tree/master/example
[example-folder-navlink]: https://github.com/EmilTholin/svelte-routing/tree/master/example/src/components/NavLink.svelte