Svelte Support
tsdown supports building Svelte component libraries by integrating rollup-plugin-svelte. This setup compiles .svelte components and bundles them alongside your TypeScript sources.
Quick Start
For the fastest way to get started, use the Svelte component starter template. This starter project comes pre-configured for Svelte library development.
bash
npx create-tsdown@latest -t svelteMinimal Example
Configure tsdown for a Svelte library with the following tsdown.config.ts:
ts
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() })],
})Install the required dependencies:
sh
npm install -D rollup-plugin-svelte svelte svelte-preprocesssh
pnpm add -D rollup-plugin-svelte svelte svelte-preprocesssh
yarn add -D rollup-plugin-svelte svelte svelte-preprocesssh
bun add -D rollup-plugin-svelte svelte svelte-preprocessHow It Works
rollup-plugin-sveltecompiles.sveltesingle-file components.tsdownbundles the compiled output with your TypeScript sources.
INFO
Generating .d.ts for Svelte components typically requires integrating svelte2tsx. We recommend using the dedicated Svelte template, which includes an emission step based on svelte2tsx to generate declarations after bundling.