This project demonstrates how to build and export Svelte 5 components using Rollup. It showcases a pattern for bundling components into standalone JavaScript modules that can be used in various environments.
This project is not a component library, but rather an educational example showing:
src/lib/
- A folder to place your Svelte componentssrc/svelte.js
- Exports the Svelte 5 runtimerollup.config.js
- Rollup configurationindex.html
- Example usageThe Rollup configuration automatically detects and builds all Svelte components in the src/lib
directory. For each component:
<!-- Include the component's CSS -->
<link rel="stylesheet" href="dist/component.css" />
<!-- Load the Svelte bundle -->
<script type="importmap">
{
"imports": {
"svelte": "./dist/svelte.js",
"svelte/internal/client": "./dist/svelte.js"
}
}
</script>
<!-- Set up the mount point -->
<div id="root"></div>
<!-- Import and mount the component -->
<script type="module">
import { mount } from "svelte";
import Component from "./dist/component.js";
const app = mount(Component, {
target: document.getElementById("root"),
props: {
// Your props here
},
});
</script>
To add new components:
.svelte
file in the src/lib
directoryThis example is not tested with .svelte.js
files. If you want to use them, you'll probably need to modify the rollup.config.js
file.
This project is released into the public domain under the Creative Commons Zero (CC0) license. You are free to use, modify, and distribute the code without any restrictions.