参加在线会议:东部夏令时周四上午 11 点,Storybook 9 发布及 AMA
文档
Storybook 文档

构建

父级:main.js|ts 配置

类型:TestBuildConfig

提供配置选项,用于优化 Storybook 的生产构建输出。

test

类型:TestBuildFlags

{
  disableBlocks?: boolean;
  disabledAddons?: string[];
  disableMDXEntries?: boolean;
  disableAutoDocs?: boolean;
  disableDocgen?: boolean;
  disableSourcemaps?: boolean;
  disableTreeShaking?: boolean;
 
}

配置 Storybook 的生产构建,以便进行性能测试,方法是禁用构建中的某些功能。运行 build-storybook 时,通过设置 --test 标志 来启用此功能。

当向 storybook build 命令提供 --test 标志时,本文档中的选项会自动启用。我们建议仅在您需要为项目禁用特定功能或调试构建问题时,才覆盖这些选项。

test.disableBlocks

类型:boolean

从构建中排除 @storybook/addon-docs/blocks 模块,该模块使用 文档块 生成自动文档。

.storybook/main.ts
// 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)'],
  build: {
    test: {
      disableBlocks: false,
    },
  },
};
 
export default config;

test.disabledAddons

类型:string[]

设置将在构建输出中禁用的插件列表。

.storybook/main.ts
// 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)'],
  addons: ['@storybook/addon-a11y', '@storybook/addon-vitest'],
  build: {
    test: {
      disabledAddons: ['@storybook/addon-a11y'],
    },
  },
};
 
export default config;

test.disableMDXEntries

类型:boolean

启用此选项会从构建中移除用户以 MDX 格式编写的文档条目。

.storybook/main.ts
// 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)'],
  build: {
    test: {
      disableMDXEntries: false,
    },
  },
};
 
export default config;

test.disableAutoDocs

类型:boolean

阻止使用 autodocs 功能自动生成的文档包含在构建中。

.storybook/main.ts
// 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)'],
  build: {
    test: {
      disableAutoDocs: false,
    },
  },
};
 
export default config;

test.disableDocgen

类型:boolean

使用任何受支持的静态分析工具(基于您使用的框架),禁用 自动 argType 和组件属性推断。

.storybook/main.ts
// 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)'],
  build: {
    test: {
      disableDocgen: false,
    },
  },
};
 
export default config;

test.disableSourcemaps

类型:boolean

覆盖生成构建源地图的默认行为。

.storybook/main.ts
// 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)'],
  build: {
    test: {
      disableSourcemaps: false,
    },
  },
};
 
export default config;

test.disableTreeShaking

类型:boolean

禁用构建中的 tree shaking

.storybook/main.ts
// 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)'],
  build: {
    test: {
      disableTreeShaking: false,
    },
  },
};
 
export default config;