Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

vite-plugin-svelte-anywhere

vidschofelix15.8kMIT2.2.2TypeScript support: included

Use Svelte components anywhere

vite, svelte, vite-plugin, custom-elements, shadow-dom, web-components

readme

logo

Vite Plugin: Svelte Anywhere

NPM Version NPM Downloads Build Status License

Use Svelte components anywhere HTML is accepted.

This Vite plugin lets you define custom elements right inside your Svelte components—just add an annotation, and you're ready to embed them in any environment, from static HTML to legacy backends or CMS platforms.

No boilerplate. No runtime shenanigans. Just Svelte, anywhere.


Features

  • 🧩 Custom Elements from Svelte — Turn any Svelte component into a reusable HTML element with a single comment.
  • 🛠 Zero Boilerplate — No manual registration or wrapper code.
  • 🔁 Dev + Prod Ready — Works with Vite HMR dev server and production builds
  • 🌓 Shadow DOM Control — Opt-in or out with simple config.
  • Lazy/Eager/Custom Templates — Choose how your components are loaded.


Quick Example

<!-- @custom-element my-counter shadow="open" template="lazy" -->
<script>
  let { count = 0 } = $props();
</script>

<button onclick={() => count++}>
  Clicked {count} times
</button>

Now just use it anywhere:

<my-counter count="5"></my-counter>