Ian VanSchooten 1147d8077d Merge remote-tracking branch 'origin/next' into vite/peer-dep
# Conflicts:
#	code/frameworks/sveltekit/package.json
#	code/yarn.lock
2022-12-16 07:52:44 -05:00

37 lines
1.1 KiB
TypeScript

import { type StorybookConfig, hasVitePlugins } from '@storybook/builder-vite';
import { handleSvelteKit } from './utils';
import { svelteDocgen } from './plugins/svelte-docgen';
export const core: StorybookConfig['core'] = {
builder: '@storybook/builder-vite',
renderer: '@storybook/svelte',
};
export const viteFinal: NonNullable<StorybookConfig['viteFinal']> = async (config, options) => {
const { plugins = [] } = config;
// TODO: set up eslint import to use typescript resolver
// eslint-disable-next-line import/no-unresolved
const { svelte, loadSvelteConfig } = await import('@sveltejs/vite-plugin-svelte');
const svelteOptions: Record<string, any> = await options.presets.apply(
'svelteOptions',
{},
options
);
const svelteConfig = { ...(await loadSvelteConfig()), ...svelteOptions };
// Add svelte plugin if not present
if (!(await hasVitePlugins(plugins, ['vite-plugin-svelte']))) {
plugins.push(svelte());
}
// Add docgen plugin
plugins.push(svelteDocgen(svelteConfig));
await handleSvelteKit(plugins, options);
return {
...config,
plugins,
};
};