babel
類型: (config: Babel.Config, options: Options) => Babel.Config | Promise<Babel.Config>
自訂 Storybook 的 Babel 設定。
擴充套件作者應使用 babelDefault
替代,其會在任何使用者預設配置套用前,先套用至預覽配置。
.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
只有在您啟用 @storybook/addon-webpack5-compiler-babel
擴充套件後,Babel 提供的選項才適用。
如果您有現有的 Babel 設定檔 (例如,.babelrc
),Storybook 將會自動偵測並使用,無需任何額外設定。
Options
類型: { configType?: 'DEVELOPMENT' | 'PRODUCTION' }
還有其他選項難以在此文件中說明。請檢視類型定義以取得更多資訊。