@ogygia/tsdown-plugin-svelte
Rolldown
The plugin uses only standard build hooks, so it also works in a plain rolldown build. Set up one output file per source file and the .ts declarations yourself, which tsdown would otherwise give it.
On this page
tsdown runs on rolldown, and the plugin uses only two standard build hooks, buildStart and writeBundle, and this.emitFile, so it also works in a plain rolldown build. This setup was tested with rolldown 1.2.16 and rolldown-plugin-dts 0.28. You set up the two things tsdown would otherwise give it:
- One output file per source file, so a component’s
./util.tsimport finds./util.jsbeside it:preserveModuleswithpreserveModulesRoot: 'src', andentryFileNames: '[name].js'. - Types for your
.tsfiles: rolldown-plugin-dts, the plugin tsdown uses. This plugin only adds the.svelte.d.tsfiles.
import { defineConfig } from 'rolldown';
import { dts } from 'rolldown-plugin-dts';
import { svelte } from '@ogygia/tsdown-plugin-svelte';
export default defineConfig({
input: ['src/index.ts', 'src/util.ts'],
external: ['svelte', /\.svelte$/],
plugins: [dts(), svelte()],
output: {
dir: 'dist',
format: 'esm',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: '[name].js'
}
});Output folder
Set the plugin’s out to output.dir when that isn’t dist. Unlike tsdown, rolldown doesn’t empty the folder first, so stale files from an earlier build stay unless you remove them.
import { defineConfig } from 'rolldown';
import { dts } from 'rolldown-plugin-dts';
import { svelte } from '@ogygia/tsdown-plugin-svelte';
export default defineConfig({
input: ['src/index.ts'],
external: ['svelte', /\.svelte$/],
plugins: [dts(), svelte({ out: 'build' })],
output: {
dir: 'build',
format: 'esm',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: '[name].js'
}
});