staticDirs
Parent: main.js|ts configuration
Type: (string | { from: string; to: string })[]
Sets a list of directories of static files to be loaded by Storybook.
.storybook/main.ts
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
staticDirs: ['../public', '../static'],
};
export default config;When using Vite-based frameworks, the files in Vite's publicDir are served and copied automatically, as if it were the first entry of staticDirs. Storybook's own files, such as index.json, and your staticDirs take precedence when file names conflict.
With configuration objects
You can also use a configuration object to define the directories:
.storybook/main.ts
// Replace your-framework with the framework you are using, e.g. react-vite, nextjs, vue3-vite, etc.
import type { StorybookConfig } from '@storybook/your-framework';
const config: StorybookConfig = {
framework: '@storybook/your-framework',
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
staticDirs: [{ from: '../my-custom-assets/images', to: '/assets' }],
};
export default config;