typescript
¥Parent: main.js|ts configuration
类型:
¥Type:
{
check?: boolean;
checkOptions?: CheckOptions;
reactDocgen?: 'react-docgen' | 'react-docgen-typescript' | false;
reactDocgenTypescriptOptions?: ReactDocgenTypescriptOptions;
skipCompiler?: boolean;
}配置 Storybook 如何处理 TypeScript 文件。
¥Configures how Storybook handles TypeScript files.
check
类型:boolean
¥Type: boolean
可选择运行 fork-ts-checker-webpack-plugin。请注意,由于这使用了 Webpack 插件,因此只有在使用 Webpack 构建器 时才可用。
¥Optionally run fork-ts-checker-webpack-plugin. Note that because this uses a Webpack plugin, it is only available when using the Webpack builder.
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
typescript: {
check: true,
},
};
export default config;checkOptions
类型:CheckOptions
¥Type: CheckOptions
如果是 enabled,则传递给 fork-ts-checker-webpack-plugin 的选项。参见 可用选项的文档。
¥Options to pass to fork-ts-checker-webpack-plugin, if enabled. See docs for available options.
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
typescript: {
check: true,
checkOptions: {
eslint: true,
},
},
};
export default config;reactDocgen
类型:'react-docgen' | 'react-docgen-typescript' | false
¥Type: 'react-docgen' | 'react-docgen-typescript' | false
默认:
¥Default:
-
false:如果未安装@storybook/react¥
false: if@storybook/reactis not installed -
'react-docgen':如果安装了@storybook/react¥
'react-docgen': if@storybook/reactis installed
配置 Storybook 用于解析 React 组件的库(如果有),react-docgen 或 react-docgen-typescript。设置为 false 以禁用解析 React 组件。react-docgen-typescript 调用 TypeScript 编译器,这使其速度变慢但通常准确。react-docgen 执行自己的分析,速度更快但不完整。
¥Configures which library, if any, Storybook uses to parse React components, react-docgen or react-docgen-typescript. Set to false to disable parsing React components. react-docgen-typescript invokes the TypeScript compiler, which makes it slow but generally accurate. react-docgen performs its own analysis, which is much faster but incomplete.
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
typescript: {
reactDocgen: 'react-docgen',
},
};
export default config;reactDocgenTypescriptOptions
类型:ReactDocgenTypescriptOptions
¥Type: ReactDocgenTypescriptOptions
如果启用了 react-docgen-typescript,则配置传递给 react-docgen-typescript-plugin 的选项。有关可用选项 适用于 Webpack 项目 或 适用于 Vite 项目,请参阅文档。
¥Configures the options to pass to react-docgen-typescript-plugin if react-docgen-typescript is enabled. See docs for available options for Webpack projects or for Vite projects.
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
typescript: {
reactDocgen: 'react-docgen-typescript',
reactDocgenTypescriptOptions: {
shouldExtractLiteralValuesFromEnum: true,
// 👇 Default prop filter, which excludes props from node_modules
propFilter: (prop) => (prop.parent ? !/node_modules/.test(prop.parent.fileName) : true),
},
},
};
export default config;skipCompiler
类型:boolean
¥Type: boolean
禁用通过编译器解析 TypeScript 文件,该编译器用于 Webpack5。
¥Disable parsing of TypeScript files through the compiler, which is used for Webpack5.
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
typescript: {
skipCompiler: true,
},
};
export default config;