> [!NOTE] > Community add-ons are currently **experimental**. The API may change. Don't use them in production yet! This guide covers how to create, test, and publish community add-ons for `sv`. ## Quick start The easiest way to create an add-on is using the addon template: ```sh npx sv create --template addon my-addon cd my-addon ``` ## Add-on structure Typically, an add-on looks like this: _hover keywords in the code to have some more context_ ```js import { transforms, svelte } from '@sveltejs/sv-utils'; import { defineAddon, defineAddonOptions } from 'sv'; // Define options that will be prompted to the user (or passed as arguments) const options = defineAddonOptions() .add('who', { question: 'To whom should the addon say hello?', type: 'string' // boolean | number | select | multiselect }) .build(); // your add-on definition, the entry point export default defineAddon({ id: 'your-addon-name', // shortDescription: 'does X', // optional: one-liner shown in prompts // homepage: 'https://...', // optional: link to docs/repo options, // preparing step, check requirements and dependencies setup: ({ dependsOn }) => { dependsOn('tailwindcss'); }, // actual execution of the addon run: ({ isKit, cancel, sv, options, directory }) => { if (!isKit) return cancel('SvelteKit is required'); // Add "Hello [who]!" to the root page sv.file( directory.routes + '/+page.svelte', transforms.svelte((ast) => { svelte.addFragment(ast, `
Hello ${options.who}!
`); }) ); } }); ``` > `sv` owns the file system — `sv.file()` resolves the path, reads the file, applies the transform, and writes the result. > `@sveltejs/sv-utils` owns the content — `transforms.svelte()` handles parsing, gives you the AST, and serializes back. See [sv-utils](/docs/cli/sv-utils) for the full API. ## Development with `file:` protocol While developing your add-on, you can test it locally using the `file:` protocol: ```sh # In your test project npx sv add file:../path/to/my-addon ``` This allows you to iterate quickly without publishing to npm. ## Testing with `sv/testing` The `sv/testing` module provides utilities for testing your add-on: ```js import { setupTest } from 'sv/testing'; import { test, expect } from 'vitest'; import addon from './index.js'; test('adds hello message', async () => { const { content } = await setupTest({ addon, options: { who: 'World' }, files: { 'src/routes/+page.svelte': '