@histoire/plugin-svelte
Version:
Histoire plugin for Svelte 4/5 and SvelteKit 2/3 support
27 lines (26 loc) • 1.15 kB
JavaScript
/** Keep Kit's aliases and virtual modules while Histoire owns HTML and middleware. */
export function isolateSvelteKit() {
return {
name: 'histoire:sveltekit-middleware',
enforce: 'post',
config: {
order: 'post',
/** Kit's custom app middleware is removed; restore Histoire's SPA fallback. */
handler: (_config, environment) => ({
appType: 'spa',
// Kit's removed application compiler normally injects this payload in
// production. Histoire mounts stories without a Kit application shell.
...(environment.command === 'build' ? { define: { __SVELTEKIT_PAYLOAD__: '{}' } } : {}),
}),
},
/** Kit 3 moved SSR middleware from compile into setup; previews need no Kit SSR. */
configResolved(config) {
for (const plugin of config.plugins) {
if (plugin.name !== 'vite-plugin-sveltekit-setup')
continue;
plugin.configureServer = undefined;
plugin.configurePreviewServer = undefined;
}
},
};
}