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

Export vite-plugin-sveltekit for usage without Sveltekit CLI. #4223

Closed
kwangure opened this issue Mar 5, 2022 · 1 comment
Closed

Export vite-plugin-sveltekit for usage without Sveltekit CLI. #4223

kwangure opened this issue Mar 5, 2022 · 1 comment
Milestone

Comments

@kwangure
Copy link
Contributor

kwangure commented Mar 5, 2022

Describe the problem

It's currently not straight forward to build on top of Sveltekit since the CLI manages all our interactions with Sveltekit core. Since the refactor of Sveltkit core into a plugin, the path to making Sveltekit usable as a Vite plugin seems more tenable with a few modifactions. With the exception of the CLI, Sveltekit-package and adapters much of the framework's functionality lives in the internal plugins already.

Reasons to export the plugin publicly:

  • It's necessary for to build a meta-framework on top of Sveltekit
  • Sveltekit would be easier to incorporate/migrate into a project already using Vite
  • Tooling (e.g IDE or CI) can initiate Svelte kit programmatically without needing CLI
  • Chrome extensions
    • In an extension, HTML files are the routes, so every page is essentially a Sveltekit instance. Coordinating this in a meta-framework setup is only possible if Sveltekit lends itself to easy programmatic control. Otherwise it's a mess -- I speak from experience.
  • It's in the spirit of embracing Vite e.g. Leverage Vite as much as possible #3659.
  • Other tooling such as Vitest can use Sveltekit resolve alias etc.

Describe the proposed solution

I imagine having the packages @sveltejs/vite-plugin-sveltekit and @sveltejs/vite-plugin-sveltekit/core.

@sveltejs/vite-plugin-sveltekit would be targeted at userland, and would be something like:

import kit from `@sveltejs/vite-plugin-sveltekit/core`;
import svelte from '@sveltejs/vite-plugin-svelte';

export default function vitePluginSveltekit(options) {
	const { kitOptions, svelteOptions } = options;

	// Vite flattens arrays of plugins
	return [
		svelte(svelteOptions),
		kit(kitOptions),
	];
}

and @sveltejs/vite-plugin-sveltekit/core would look like:

export default function sveltekitCore(options) {
	return {
		config(_config) {
			// Add internal Sveltekit config e.g $lib and $app aliases
		}
		configResolved(_config) {
			// Vite config validation now goes here...
		}
		// ... rest of core hooks
	}
}

and integrated into other setups like:

import kit from `@sveltejs/vite-plugin-sveltekit/core`;
import svelte from '@sveltejs/vite-plugin-svelte';

export default function vitePluginSuperDuperSveltekit(options) {
	const { kitOptions, svelteOptions } = options;

	// Vite flattens arrays of plugins
	return [
		svelte(svelteOptions),
		kit(kitOptions),
		{
			name: "super-duper-sveltekit",
			// ...
		}
	];
}

I admittedly haven't thought too much how adapters fit into the picture since I'm not yet intimate with how they actually work.

Alternatives considered

Add Sveltekit hooks. I haven't thought deeply about how this would look like but adding a plugin system on top of Svelkit might achieve something similar but it's additional overhead/maintenance for a less universally useful (read worse) outcome.

Importance

would make my life easier

Additional Information

No response

@Rich-Harris Rich-Harris added this to the post-1.0 milestone Apr 25, 2022
@benmccann
Copy link
Member

Done in #5094

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants