Skip to content

Commit

Permalink
Merge pull request #26860 from yuemori/fix-vite-builder-override-asse…
Browse files Browse the repository at this point in the history
…tsinclude

Vite: Merge assetsInclude property with Storybook default values
(cherry picked from commit f6ecc28)
  • Loading branch information
ndelangen authored and storybook-bot committed May 2, 2024
1 parent bf62de5 commit 97944e0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
15 changes: 15 additions & 0 deletions code/builders/builder-vite/src/assetsInclude.ts
Original file line number Diff line number Diff line change
@@ -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];
}
}
3 changes: 2 additions & 1 deletion code/builders/builder-vite/src/vite-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down

0 comments on commit 97944e0

Please sign in to comment.