2022-09-02 23:54:15 +08:00

32 lines
832 B
TypeScript

import path from 'path';
import fs from 'fs';
import type { StorybookConfig } from '@storybook/builder-vite';
import { svelteDocgen } from './plugins/svelte-docgen';
export const addons: StorybookConfig['addons'] = ['@storybook/svelte'];
export const core: StorybookConfig['core'] = {
builder: '@storybook/builder-vite',
};
export function readPackageJson(): Record<string, any> | false {
const packageJsonPath = path.resolve('package.json');
if (!fs.existsSync(packageJsonPath)) {
return false;
}
const jsonContent = fs.readFileSync(packageJsonPath, 'utf8');
return JSON.parse(jsonContent);
}
export const viteFinal: StorybookConfig['viteFinal'] = async (config, { presets }) => {
const { plugins = [] } = config;
plugins.push(svelteDocgen(config) as any);
return {
...config,
plugins,
};
};