From da3986ff48f1c8aae705da51979c6a126912a937 Mon Sep 17 00:00:00 2001 From: Norbert de Langen Date: Mon, 29 Apr 2024 16:47:36 +0200 Subject: [PATCH] Merge pull request #26860 from yuemori/fix-vite-builder-override-assetsinclude Vite: Merge assetsInclude property with Storybook default values (cherry picked from commit f6ecc28d2a11fccd7d36a2db578bdaa30b41e89d) --- code/builders/builder-vite/src/assetsInclude.ts | 15 +++++++++++++++ code/builders/builder-vite/src/vite-server.ts | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 code/builders/builder-vite/src/assetsInclude.ts diff --git a/code/builders/builder-vite/src/assetsInclude.ts b/code/builders/builder-vite/src/assetsInclude.ts new file mode 100644 index 000000000000..b71388ea2d17 --- /dev/null +++ b/code/builders/builder-vite/src/assetsInclude.ts @@ -0,0 +1,15 @@ +import type { InlineConfig as ViteInlineConfig } from 'vite'; + +export function getAssetsInclude(config: ViteInlineConfig, newPath: string[]): (string | RegExp)[] { + const { assetsInclude } = config; + + if (!assetsInclude) { + return newPath; + } + + if (Array.isArray(assetsInclude)) { + return [...assetsInclude, ...newPath]; + } else { + return [assetsInclude, ...newPath]; + } +} diff --git a/code/builders/builder-vite/src/vite-server.ts b/code/builders/builder-vite/src/vite-server.ts index 0b1e80435027..cfd3c4051a3e 100644 --- a/code/builders/builder-vite/src/vite-server.ts +++ b/code/builders/builder-vite/src/vite-server.ts @@ -3,6 +3,7 @@ import type { Options } from '@storybook/types'; import { commonConfig } from './vite-config'; import { getOptimizeDeps } from './optimizeDeps'; import { sanitizeEnvVars } from './envs'; +import { getAssetsInclude } from './assetsInclude'; export async function createViteServer(options: Options, devServer: Server) { const { presets } = options; @@ -12,7 +13,7 @@ export async function createViteServer(options: Options, devServer: Server) { const config = { ...commonCfg, // Needed in Vite 5: https://github.com/storybookjs/storybook/issues/25256 - assetsInclude: ['/sb-preview/**'], + assetsInclude: getAssetsInclude(commonCfg, ['/sb-preview/**']), // Set up dev server server: { middlewareMode: true,