previewBody
父级: main.js|ts 配置
类型: (body: string) => string
以编程方式调整 Storybook 预览 <body>
。最常被 插件作者 使用。
如果你不需要以编程方式调整预览主体,可以将脚本和样式添加到 preview-body.html
中。
例如,你可以根据环境条件添加脚本或样式
.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)'],
previewBody: (body) => `
${body}
${
process.env.ANALYTICS_ID ? '<script src="https://cdn.example.com/analytics.js"></script>' : ''
}
`,
};
export default config;