Configure Storybook in seconds
Storybook is an isolated workshop for building and testing UI components, and every project needs a .storybook folder with a main file telling it where stories live, which framework builder to use, and which addons to load. This builder generates a clean, typed main.ts plus a sensible preview.ts so you can scaffold a new Storybook or align an old one with current conventions.
How it works
Storybook reads .storybook/main.ts at startup. The stories array is a glob that Storybook scans to find every *.stories.* file. The framework object selects the compiler and renderer — this is the single most important setting, because it must match your bundler (Vite or Webpack) and UI library (React, Vue, Angular, Svelte). The addons array lists plugins that extend the toolbar and docs.
The generated preview.ts sets global parameters: an actions matcher that auto-detects on* event props, and controls matchers that render color pickers and date pickers based on prop-name patterns. The staticDirs option tells Storybook to serve assets like images or fonts from your public folder, and docs.autodocs: "tag" auto-generates documentation pages.
Tips and notes
- Install each addon you enable; the config only references the package names.
- The stories glob is relative to the
.storybookfolder, so../src/**points at your source directory. - For a TypeScript project keep
main.ts; for plain JavaScript rename tomain.jsand remove theimport typeline and theStorybookConfigannotation. staticDirsaccepts multiple comma-separated paths if you serve assets from more than one folder.