1.4 KiB
1.4 KiB
Svelte Support
Build Svelte component libraries with tsdown using rollup-plugin-svelte.
Quick Start
npx create-tsdown@latest -t svelte
Configuration
import svelte from 'rollup-plugin-svelte'
import { sveltePreprocess } from 'svelte-preprocess'
import { defineConfig } from 'tsdown'
export default defineConfig({
entry: ['./src/index.ts'],
platform: 'neutral',
plugins: [svelte({ preprocess: sveltePreprocess() })],
})
Dependencies
npm install -D rollup-plugin-svelte svelte svelte-preprocess
Distribution Strategy
Recommended: Ship .svelte source files instead of precompiled JS. Let consumers' tooling (Vite + @sveltejs/vite-plugin-svelte) compile in their apps.
Reasons:
- Avoids version compatibility issues with
svelte/internal - Better SSR/hydration consistency
- Consumers get better HMR, diagnostics, and tree-shaking
- Fewer republish cycles on Svelte upgrades
Exceptions where shipping JS makes sense:
- Web Components via
customElementmode - CDN direct-load without a build step
Key Points
- Mark
svelte/svelte/*as external; declaresvelteinpeerDependencies - Use
svelte2tsxto emit.d.tsfor Svelte components - Keep
.sveltein source form for distribution
Related
- Plugins - Plugin configuration
- Dependencies - External dependencies