What Storybook Does
- Isolated development — components render without app shell
- Interactive docs — auto-generated from stories + MDX
- Visual testing — Chromatic integration for snapshots
- Accessibility — a11y addon flags WCAG issues
- Interaction tests — Testing Library inside stories
- Args/Controls — live-edit props in the UI
- Multi-framework — React, Vue, Svelte, Angular, Web Components, Solid
Architecture
Storybook runs as a dev server alongside your app. Each *.stories.tsx file exports stories that Storybook auto-discovers. Uses Vite or Webpack under the hood. Addons extend the UI panel (docs, a11y, viewport, theme, etc.).
Self-Hosting
# Build static site
npm run build-storybook
# Outputs storybook-static/
# Deploy anywhere: Netlify, Vercel, S3, GitHub PagesKey Features
- Framework-agnostic (10+ frameworks)
- MDX documentation
- CSF 3 (Component Story Format)
- Controls/Actions addons
- Accessibility (a11y) addon
- Visual regression via Chromatic
- Interaction testing
- Theme switching
- Responsive viewport testing
Comparison
| Tool | Scope | Isolation | Docs |
|---|---|---|---|
| Storybook | UI workshop | Yes | MDX + auto |
| Ladle | Stories only | Yes | Basic |
| Histoire | Vue-first | Yes | Good |
| Docz | Docs | Partial | MDX |
常见问题 FAQ
Q: 和单元测试冲突吗? A: 不。Storybook 做可视化+交互测试,Vitest/Jest 做逻辑单元测试。可组合(Storybook Test Runner + Playwright)。
Q: 构建速度慢? A: 迁移到 Storybook 7+ 的 Vite builder 大幅提速。冷启动从分钟级降到秒级。
Q: 生产会打包吗? A: 不会。Storybook 是 devDependency,只在开发和 CI 运行。
来源与致谢 Sources
- Docs: https://storybook.js.org
- GitHub: https://github.com/storybookjs/storybook
- License: MIT