Skip to content

Bring @sveltejs/kit/experimental/vite out of experimental #5184

@benmccann

Description

@benmccann

Describe the problem

Right now SvelteKit asks users to pass Vite configuration via the kit.vite option in svelte.config.js. This was originally nice because it means less config files and gives SvelteKit a bit more control. However, it's also non-standard. Tools like Vitest and Storybook look for a vite.config.js to read configuration from and it would be nice to support those tools out-of-the-box

Describe the proposed solution

#5094 creates a SvelteKit plugin that can be imported in a vite.config.js. If a vite.config.js is created, it is expected that Vite config is no longer specified in svelte.config.js, but in vite.config.js.

This new feature can be used like:

// vite.config.js
import { sveltekit } from '@sveltejs/kit/experimental/vite';

/** @type {import('vite').UserConfig} */
const config = {
  plugins: [sveltekit()]
};

export default config;

Cleanup items

If we decide that we like this approach (and I think we probably will) then it would make sense to make some changes:

  • Make vite.config.js mandatory
  • Add it to project templates
  • Get rid of config.kit.vite
  • Move @sveltejs/kit/experimental/vite to @sveltejs/kit/vite or @sveltejs/vite-plugin-sveltekit
  • Update contributing guide with new code locations
  • Add vitest option to create-svelte
  • More controversially, we might want to get rid of svelte-kit dev/build/preview in favour of using vite dev/build/preview. This would mean that SvelteKit itself would no longer have a dependency on Vite, other than in the plugin; apps themselves would need to have a devDependency on vite
    • Consequently, figure out how to handle versions. It's likely that SvelteKit will expect a particular version of Vite, which might mean it needs to become a peerDependency if it's no longer a dependency (though if it's possible to avoid depending on a specific version, that would be ideal)

Alternatives considered

No response

Importance

nice to have

Additional Information

CC people who might be interested in this: @nickbreaton @JessicaSachs @IanVS @brittneypostma

Please feel free to share with others. I haven't used Storybook, Vitest, Histoire, etc. before so would love any help in testing! And would love tips on things we might want to document for the community to setup these tools. Whether there's something that needs to be improved or everything works, I'd love to hear about it either way!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions