diff --git a/code/lib/core-server/src/presets/common-preset.ts b/code/lib/core-server/src/presets/common-preset.ts index 299b97cced9..f80152f0cf8 100644 --- a/code/lib/core-server/src/presets/common-preset.ts +++ b/code/lib/core-server/src/presets/common-preset.ts @@ -22,13 +22,15 @@ import { parseStaticDir } from '../utils/server-statics'; const defaultFavicon = require.resolve('@storybook/core-server/public/favicon.svg'); -export const defaultStaticDirs = { - from: join(dirname(require.resolve('@storybook/manager/package.json')), 'static'), - to: '/sb-common-assets', -}; +export const defaultStaticDirs = [ + { + from: join(dirname(require.resolve('@storybook/manager/package.json')), 'static'), + to: '/sb-common-assets', + }, +]; export const staticDirs: PresetPropertyFn<'staticDirs'> = async (values = []) => [ - { ...defaultStaticDirs }, + ...defaultStaticDirs, ...values, ]; diff --git a/code/lib/core-server/src/utils/server-statics.ts b/code/lib/core-server/src/utils/server-statics.ts index 2ecc3e8fc22..5af31c21a1a 100644 --- a/code/lib/core-server/src/utils/server-statics.ts +++ b/code/lib/core-server/src/utils/server-statics.ts @@ -4,16 +4,24 @@ import { getDirectoryFromWorkingDir } from '@storybook/core-common'; import chalk from 'chalk'; import express from 'express'; import { pathExists } from 'fs-extra'; -import path from 'path'; +import path, { dirname, join } from 'path'; import favicon from 'serve-favicon'; +import isEqual from 'lodash/isEqual.js'; import { dedent } from 'ts-dedent'; +const defaultStaticDirs = [ + { + from: join(dirname(require.resolve('@storybook/manager/package.json')), 'static'), + to: '/sb-common-assets', + }, +]; + export async function useStatics(router: any, options: Options) { const staticDirs = await options.presets.apply('staticDirs'); const faviconPath = await options.presets.apply('favicon'); - if (staticDirs && options.staticDir) { + if (staticDirs && options.staticDir && !isEqual(staticDirs, defaultStaticDirs)) { throw new Error(dedent` Conflict when trying to read staticDirs: * Storybook's configuration option: 'staticDirs' @@ -23,9 +31,10 @@ export async function useStatics(router: any, options: Options) { `); } - const statics = staticDirs - ? staticDirs.map((dir) => (typeof dir === 'string' ? dir : `${dir.from}:${dir.to}`)) - : options.staticDir; + const statics = + staticDirs && !isEqual(staticDirs, defaultStaticDirs) + ? staticDirs.map((dir) => (typeof dir === 'string' ? dir : `${dir.from}:${dir.to}`)) + : options.staticDir; if (statics && statics.length > 0) { await Promise.all(