This project serves as a custom component registry for shadcn-svelte. It allows you to develop, document, and distribute your own Svelte components that can be added to any SvelteKit project using the shadcn-svelte CLI.
It's essential to understand the two main directories for components:
-
src/lib/components/ui(Internal Development) This is where you should develop, test, and refine your components. Think of it as your workshop. The components in this directory are used for local development, visualization in Storybook, and are the "source of truth" for your component's code. -
src/lib/registry(Public Registry) This directory contains the files that are prepared for distribution. When a user adds a component using the CLI, the files are served from here. The structure in this directory defines what code gets delivered to the end-user. It might be a direct copy of a component fromsrc/lib/components/ui, or it could be a more complex "block" composed of multiple files.
This separation allows you to have extensive documentation, examples, and tests for your internal components without bloating the code that gets shipped to the consumer.
pnpm installFor live-reloading and a visual environment to build your components:
# Run the SvelteKit dev server
pnpm dev
# Run Storybook to see your internal components
pnpm storybookHere is the standard workflow for adding a new component to the registry.
- For a simple UI component: Create a new file such as
avatar.svelteinsidesrc/lib/registry/ui/. - For a complex "Block" component: Create a new directory like
src/lib/registry/blocks/data-table/and add all the files that should be included when a user installs that block.
For example, to create a new avatar component:
- Create the component directory:
src/lib/registry/ui/avatar/ - Create the Svelte file:
avatar.svelte - Create an
index.tsto export it:export { default as Avatar } from './avatar.svelte' - (optional) Create a Storybook story (
src/stories/Avatar.stories.svelte) to view and test it in isolation.
Add a new entry to the items array in the registry.json file. This entry tells the shadcn-svelte CLI where to find the component's files.
Crucially, the files.path property must point to the component's location within the src/lib/registry directory.
Example for a simple avatar component:
{
"name": "avatar",
"type": "registry:component",
"title": "Avatar",
"description": "An image element with a fallback for representing a user.",
"dependencies": ["@lucide/svelte"],
"registryDependencies": ["card", "button", "separator"],
"files": [
{
"path": "src/lib/registry/ui/avatar.svelte",
"type": "registry:component"
}
]
}After adding your component to registry.json, run the build command. This generates the final JSON definitions in the static/r directory that the CLI will consume.
pnpm build:registryCreate a new folder with your components slug inside routes/components and create a new +page.svelte. Like the other example pages, build a demo page by using the ComponentPageWrapper. You will also need a page.server.ts with a simple load function and the components slug (refer to the other component's pages).
Once the registry is built and the project is hosted, users can add your components to their projects with the CLI:
pnpm dlx shadcn-svelte@next add https://components.deckweiss.at/r/<component-name>.json