Skip to content

Commit 4db56ea

Browse files
committed
fix: default vite allowed hosts config
1 parent d7a4a54 commit 4db56ea

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

.changeset/great-flowers-lie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@storybook/marko-vite": minor
3+
---
4+
5+
When the `--host` cli flag is used with storybook, use that value as a default for the vite `allowedHosts` config.

packages/frameworks/marko-vite/src/preset.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ export const core: PresetProperty<"core"> = async (config, options) => {
1717
};
1818
};
1919

20-
export const viteFinal: StorybookConfig["viteFinal"] = async (baseConfig) => {
20+
export const viteFinal: StorybookConfig["viteFinal"] = async (
21+
viteConfig,
22+
storybookConfig,
23+
) => {
2124
const { mergeConfig } = await import("vite");
22-
return mergeConfig(baseConfig, {
25+
return mergeConfig(viteConfig, {
2326
resolve: {
2427
alias: [
2528
{
@@ -29,9 +32,13 @@ export const viteFinal: StorybookConfig["viteFinal"] = async (baseConfig) => {
2932
},
3033
],
3134
},
35+
server:
36+
storybookConfig.host && viteConfig.server?.allowedHosts === undefined
37+
? { allowedHosts: [storybookConfig.host] }
38+
: undefined,
3239
plugins:
3340
// Ensure @marko/vite included unless already added.
34-
(await hasVitePlugins(baseConfig.plugins || [], ["marko-vite:pre"]))
41+
(await hasVitePlugins(viteConfig.plugins || [], ["marko-vite:pre"]))
3542
? []
3643
: [(await import("@marko/vite")).default({ linked: false })],
3744
});

0 commit comments

Comments
 (0)