Skip to content

Commit 077e064

Browse files
committed
fix: fix vite storybook
1 parent 79bb847 commit 077e064

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

.storybook/main.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,18 @@ const config: StorybookConfig = {
1616
name: '@storybook/react-vite',
1717
options: {},
1818
},
19-
viteFinal: async (viteConfig) =>
20-
mergeConfig(viteConfig, {
19+
viteFinal: async (viteConfig) => {
20+
// Storybook 会合并项目的 Vite 配置;如果把应用的 HTML input 带进来,
21+
// 可能导致 storybook-static/index.html 变成主应用模板(从而 manager 资源加载失败)。
22+
const cfg: any = viteConfig
23+
if (cfg?.build?.rollupOptions?.input) {
24+
delete cfg.build.rollupOptions.input
25+
}
26+
if (cfg?.build?.outDir) {
27+
delete cfg.build.outDir
28+
}
29+
30+
return mergeConfig(viteConfig, {
2131
resolve: {
2232
alias: {
2333
'@': path.resolve(rootDir, 'src'),
@@ -51,7 +61,8 @@ const config: StorybookConfig = {
5161
build: {
5262
chunkSizeWarningLimit: 2000,
5363
},
54-
}),
64+
})
65+
},
5566
}
5667

5768
export default config

0 commit comments

Comments
 (0)