SvelteKit - build component code only - without <head> etc

Viewed 224

is there any way to let SvelteKit build only the code of one component.

E.g. lets say we have a component showing all participants of a conference. We would like to let SvelteKit generate only the

  • HTML code of this table (without <head> and without other things within <body>)
  • hydration-js for this specific table

Thanks!

3 Answers

No, that is outside the scope of SvelteKit.

It's achievable with Svelte (no Kit) by using the Svelte compiler with a custom setup.

To generate the html code you'll need to compile the components with generate: 'ssr'. That will generate the javascript you can run on the server to generate the HTML.

The compiler output is unbundled and doesn't run in a browser without bundling.
To get the "hydration-js" you'll need to compile the components again but with generate: 'dom', hydratable: true using a bundler with a svelte plugin.

Related