核心
類型
{
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 版本和生態系統更新的「新功能」通知(例如,addons、內容等)。
.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