核心
父级: main.js|ts 配置
类型
{
builder?: string | { name: string; options?: BuilderOptions };
channelOptions?: ChannelOptions;
crossOriginIsolated?: boolean;
disableProjectJson?: boolean;
disableTelemetry?: boolean;
disableWebpackDefaults?: boolean;
disableWhatsNewNotifications?: boolean;
enableCrashReports?: boolean;
renderer?: RendererName;
}
配置 Storybook 的内部功能。
builder
类型
| '@storybook/builder-vite' | '@storybook/builder-webpack5'
| {
name: '@storybook/builder-vite' | '@storybook/builder-webpack5';
options?: BuilderOptions;
}
配置 Storybook 的构建器,Vite 或 Webpack。
使用新的 框架 API,framework.options.builder
现在是配置构建器的首选方式。
只有在需要配置不属于框架一部分的构建器时,才应使用 core.builder.options
。
.storybook/main.ts
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
core: {
builder: {
name: '@storybook/builder-vite',
options: {
viteConfigPath: '../../../vite.config.js',
},
},
},
};
export default config;
channelOptions
类型: ChannelOptions
{
allowClass: boolean;
allowDate: boolean;
allowFunction: boolean;
allowRegExp: boolean;
allowSymbol: boolean;
allowUndefined: boolean;
lazyEval: boolean;
maxDepth: number;
space: number | undefined;
}
配置 Storybook 用于在管理器和预览之间通信的通道。
只有两个属性可能被使用
channelOptions.allowFunction
类型: boolean
默认值: false
启用跨通道序列化函数,这可能存在安全风险。
channelOptions.maxDepth
类型: number
默认值: 3
跨通道序列化嵌套对象的最大深度。较大的值将较慢。
crossOriginIsolated
类型: boolean
启用 CORS 标头以在“安全上下文”中运行文档。请参阅 SharedArrayBuffer 安全要求
这将在开发模式下启用这些标头
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Embedder-Policy: require-corp
.storybook/main.ts
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
core: {
crossOriginIsolated: true,
},
};
export default config;
disableProjectJson
类型: boolean
禁用生成 project.json
,这是一个包含 Storybook 元数据的文件
.storybook/main.ts
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
core: {
disableProjectJson: true,
},
};
export default config;
disableTelemetry
类型: boolean
禁用 Storybook 的遥测数据收集。
.storybook/main.ts
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
core: {
disableTelemetry: true,
},
};
export default config;
disableWebpackDefaults
类型: boolean
禁用 Storybook 的默认 Webpack 配置。
.storybook/main.ts
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
core: {
disableWebpackDefaults: true,
},
};
export default config;
disableWhatsNewNotifications
类型: boolean
禁用 UI 中新版 Storybook 和生态系统更新(例如 插件、内容 等)的“新功能”通知。
.storybook/main.ts
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
core: {
disableWhatsNewNotifications: true,
},
};
export default config;
enableCrashReports
类型: boolean
启用将崩溃报告发送到 Storybook 遥测。
.storybook/main.ts
// Replace your-framework with the framework you are using (e.g., react-webpack5, vue3-vite)
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
core: {
enableCrashReports: true, // 👈 Appends the crash reports to the telemetry events
},
};
export default config;
renderer
类型:RendererName