Docs
Storybook Docs

babel

父级:main.js|ts 配置

¥Parent: main.js|ts configuration

类型:(config: Babel.Config, options: Options) => Babel.Config | Promise<Babel.Config>

¥Type: (config: Babel.Config, options: Options) => Babel.Config | Promise<Babel.Config>

自定义 Storybook 的 Babel 设置。

¥Customize Storybook's Babel setup.

插件作者 应该改用 babelDefault,它在应用任何用户预设之前应用于预览配置。

¥Addon authors should use babelDefault instead, which is applied to the preview config before any user presets have been applied.

.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', '../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
  async babel(config, { configType }) {
    if (configType === 'DEVELOPMENT') {
      // Your development configuration goes here
    }
    if (configType === 'PRODUCTION') {
      // Your production configuration goes here.
    }
    return config;
  },
};
 
export default config;

Babel.Config

Babel 提供的选项仅在你启用了 @storybook/addon-webpack5-compiler-babel 插件时才适用。

¥The options provided by Babel are only applicable if you've enabled the @storybook/addon-webpack5-compiler-babel addon.

如果你有现有的 Babel 配置文件(例如 .babelrc),Storybook 将自动检测并使用它,而无需任何额外的配置。

¥If you have an existing Babel configuration file (e.g., .babelrc), it will be automatically detected and used by Storybook without any additional configuration required.

Options

类型:{ configType?: 'DEVELOPMENT' | 'PRODUCTION' }

¥Type: { configType?: 'DEVELOPMENT' | 'PRODUCTION' }

还有其他难以在此处记录的选项。请自省类型定义以获取更多信息。

¥There are other options that are difficult to document here. Please introspect the type definition for more information.