Skip to content

Instantly share code, notes, and snippets.

@shirakaba
Last active November 18, 2024 03:50
Show Gist options
  • Save shirakaba/2283ca9f12fcfb3e01a08c41b28b7c02 to your computer and use it in GitHub Desktop.
Save shirakaba/2283ca9f12fcfb3e01a08c41b28b7c02 to your computer and use it in GitHub Desktop.
How to configure Vite from svelte.config.js in SvelteKit projects

SvelteKit

In SvelteKit projects, SvelteKit wraps around Vite.

This example is for configuring path aliases, but you get the idea. There's a kit.vite property in svelte.config.js, and you'd configure vite through there.

https://kit.svelte.dev/faq#aliases

Vite's plugins should be API-compatible with Rollup, to my understanding.

More docs: https://kit.svelte.dev/docs#configuration-vite

Svelte

For regular Svelte projects, you'd probably use Vite directly, apparently "using Vite's CLI commands instead".

@trusktr
Copy link

trusktr commented Nov 18, 2024

This has since changed. Putting a vite object inside of kit, will now result in this error:

error during build:
Could not load svelte.config.js: Unexpected option config.kit.vite

The way to do it now is to put it in vite.config.js directly, so you have both svelte.config.js and vite.config.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment