AFFiNE/packages/frontend/component/.storybook/main.ts
pengx17 7dad9fe816
fix(component): workaround for storybook startup (#9025)
It seems starting up storybook throws error when parsing doc using typescript.
Temporarily remove reactDocgen for now.
![image.png](https://graphite-user-uploaded-assets-prod.s3.amazonaws.com/T2klNLEk0wxLh4NRDzhk/db54c528-2b37-4a91-b980-4fe6c07240b7.png)
2024-12-05 05:35:00 +00:00

81 lines
2.1 KiB
TypeScript

import { dirname, join } from 'path';
import { StorybookConfig } from '@storybook/react-vite';
import { vanillaExtractPlugin } from '@vanilla-extract/vite-plugin';
import swc from 'unplugin-swc';
import { mergeConfig } from 'vite';
import { getBuildConfig } from '@affine/cli/src/webpack/runtime-config';
export default {
stories: ['../src/ui/**/*.@(mdx|stories.@(js|jsx|ts|tsx))'],
addons: [
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@storybook/addon-interactions'),
getAbsolutePath('@storybook/addon-mdx-gfm'),
'@chromatic-com/storybook',
],
framework: {
name: getAbsolutePath('@storybook/react-vite'),
options: {},
},
features: {},
docs: {},
async viteFinal(config, _options) {
return mergeConfig(config, {
plugins: [
vanillaExtractPlugin(),
swc.vite({
jsc: {
preserveAllComments: true,
parser: {
syntax: 'typescript',
dynamicImport: true,
tsx: true,
decorators: true,
},
target: 'es2022',
externalHelpers: false,
transform: {
react: {
runtime: 'automatic',
},
useDefineForClassFields: false,
decoratorVersion: '2022-03',
},
},
sourceMaps: true,
inlineSourcesContent: true,
}),
],
define: {
'process.env.CAPTCHA_SITE_KEY': `"${process.env.CAPTCHA_SITE_KEY}"`,
...Object.entries(
getBuildConfig({
distribution: 'web',
mode: 'development',
channel: 'canary',
static: false,
coverage: false,
})
).reduce((envs, [key, value]) => {
envs[`BUILD_CONFIG.${key}`] = JSON.stringify(value);
return envs;
}, {}),
},
});
},
// typescript: {
// reactDocgen: 'react-docgen-typescript',
// },
} satisfies StorybookConfig;
function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, 'package.json')));
}