storybook-rsbuild
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStorybook Rsbuild
Storybook Rsbuild
Goal
目标
Set up Storybook on Rsbuild, or migrate an existing Storybook to it. Factual mappings — version compatibility, package names, install commands, config conversion patterns — live in upstream docs at . This skill is an action router and a behavioral checklist; it does not duplicate the docs.
storybook.rsbuild.rs在Rsbuild上设置Storybook,或是将现有Storybook迁移至Rsbuild。版本兼容性、包名、安装命令、配置转换模式等事实映射信息可在上游文档中查看。本指南是一个操作路由和行为检查清单,不会重复文档内容。
storybook.rsbuild.rsPrinciples (must follow)
原则(必须遵守)
-
Single source of truth is upstream. Fetch the relevantpage for version tables, install commands, and config conversion patterns. Do not infer version pins or package names from training memory — the ecosystem moves faster than the model's prior.
storybook.rsbuild.rs -
Pin from the framework guide's Requirements table. Each framework guide page (e.g.) carries a Requirements section listing the canonical compatible version ranges — that is the authoritative source for version pins. For fresh setups, install the latest stable
https://storybook.rsbuild.rs/guide/framework/reactmajor and the matchingstorybookmajor. Do not pin from version numbers you see in code snippets elsewhere; only the docs are authoritative.storybook-rsbuild -
Declaredirectly.
@rsbuild/corelistsstorybook-<framework>-rsbuildas a peer dependency, but you must still add@rsbuild/coreto the project's own@rsbuild/coreso version pins and lockfile audits remain unambiguous and a future framework-package release that drops the peer cannot silently break the build.devDependencies -
Migration is one task with two ordered phases — both required. Phase A: install the new framework package and update config; leave the old framework package, old builder package, and old/
webpackFinalblocks in place so Verification has a rollback path. Phase B: as soon as Verification passes, in the same task, remove the old framework package (e.g.viteFinal,@storybook/react-webpack5), the old builder package (e.g.@storybook/vue3-vite,@storybook/builder-webpack5), and the old@storybook/builder-vite/webpackFinalblock. A migration that ends with both builders' framework packages still inviteFinalis incomplete — leaving them is the most common silent regression in this skill's evals. Phase A on its own is not a valid stopping point; if you ran Verification, you must also run cleanup.package.json -
Preserve addons; never silently drop. When migrating, webpack-only addons (e.g.) must either be passed through
@storybook/addon-styling-webpack(so upstream auto-translation handles them) or replaced with the equivalent Rsbuild-native pipeline (webpackAddons,@rsbuild/plugin-postcss, etc.). A migration that removes a styling addon and produces a passingtools.postcssbut a visually broken story tree is still a regression.storybook build -
Operate in scope. In monorepos, modify only the package that hosts stories. Do not edit business source files unless the migration strictly requires it.
-
上游为唯一可信来源。获取的相关页面,以获取版本表、安装命令和配置转换模式。不要从训练记忆中推断版本固定值或包名——生态系统的更新速度快于模型的现有知识。
storybook.rsbuild.rs -
从框架指南的Requirements表中固定版本。每个框架指南页面(例如)都包含一个Requirements部分,列出了标准兼容版本范围——这是版本固定值的权威来源。对于全新搭建,安装最新稳定版的
https://storybook.rsbuild.rs/guide/framework/react主版本以及匹配的storybook主版本。不要从其他地方的代码片段中看到的版本号来固定版本;只有文档是权威的。storybook-rsbuild -
直接声明。
@rsbuild/core将storybook-<framework>-rsbuild列为peer依赖,但你仍需将@rsbuild/core添加到项目自身的@rsbuild/core中,这样版本固定值和锁文件审计才能保持明确,且未来框架包版本若移除该peer依赖也不会静默破坏构建。devDependencies -
迁移是一项包含两个有序阶段的任务——两个阶段均需完成。阶段A:安装新的框架包并更新配置;保留旧框架包、旧构建器包以及旧的/
webpackFinal代码块,以便验证阶段有回滚路径。阶段B:一旦验证通过,在同一任务中移除旧框架包(例如viteFinal、@storybook/react-webpack5)、旧构建器包(例如@storybook/vue3-vite、@storybook/builder-webpack5)以及旧的@storybook/builder-vite/webpackFinal代码块。若迁移结束后viteFinal中仍同时存在两个构建器的框架包,则视为未完成——遗留这些包是本指南评估中最常见的静默回归问题。仅完成阶段A并非有效终止点;若已执行验证,则必须执行清理步骤。package.json -
保留插件;切勿静默移除。迁移时,仅支持webpack的插件(例如)必须通过
@storybook/addon-styling-webpack传递(以便上游自动转换处理),或是替换为Rsbuild原生的等效流水线(例如webpackAddons、@rsbuild/plugin-postcss等)。若迁移移除了样式插件,导致tools.postcss执行成功但故事树显示异常,仍视为回归问题。storybook build -
在范围内操作。在单体仓库中,仅修改托管故事的包。除非迁移严格要求,否则不要编辑业务源文件。
Step 1 — Detect scenario
步骤1 — 检测场景
Read and project structure to determine existing Storybook state:
package.json- Check for directory (in monorepos, check both root and per-package)
.storybook/ - Check for
package.jsonscripts orstorybook/@storybook/*in dependencies or devDependenciesstorybook-*-rsbuild - If Storybook exists and already uses → already set up; go to Configuration or Troubleshooting as needed
storybook-*-rsbuild - If Storybook exists with a non-Rsbuild builder (,
@storybook/*-webpack5, etc.) → go to Migration Workflow@storybook/*-vite - No Storybook found → go to Fresh Setup Workflow
读取和项目结构,确定现有Storybook状态:
package.json- 检查是否存在目录(在单体仓库中,同时检查根目录和各个子包目录)
.storybook/ - 检查中的
package.json脚本,或是依赖项/开发依赖项中的storybook/@storybook/*storybook-*-rsbuild - 若Storybook已存在且已使用→ 已完成设置;根据需要跳转至配置或故障排查
storybook-*-rsbuild - 若Storybook已存在但使用非Rsbuild构建器(、
@storybook/*-webpack5等) → 跳转至迁移流程@storybook/*-vite - 未找到Storybook → 跳转至全新搭建流程
Fresh Setup Workflow
全新搭建流程
1. Detect ecosystem integration
1. 检测生态系统集成
Read dependencies and devDependencies, check in order:
package.json| Signal | Ecosystem | Integration guide |
|---|---|---|
| Rslib | https://storybook.rsbuild.rs/guide/integrations/rslib |
| Modern.js | https://storybook.rsbuild.rs/guide/integrations/modernjs |
| Pure Rspack | https://storybook.rsbuild.rs/guide/integrations/rspack |
If matched, read the integration guide and apply its constraints as an overlay alongside the steps below.
读取的依赖项和开发依赖项,按以下顺序检查:
package.json| 信号 | 生态系统 | 集成指南 |
|---|---|---|
| Rslib | https://storybook.rsbuild.rs/guide/integrations/rslib |
| Modern.js | https://storybook.rsbuild.rs/guide/integrations/modernjs |
| 纯Rspack | https://storybook.rsbuild.rs/guide/integrations/rspack |
若匹配成功,阅读集成指南并将其约束作为叠加层应用到以下步骤中。
2. Detect UI framework
2. 检测UI框架
Infer the UI framework from app dependencies (, , , etc.):
reactvuelit| UI Framework | Framework package | Guide |
|---|---|---|
| React | | https://storybook.rsbuild.rs/guide/framework/react |
| Vue 3 | | https://storybook.rsbuild.rs/guide/framework/vue |
| Vanilla JS/TS | | https://storybook.rsbuild.rs/guide/framework/vanilla |
| Web Components | | https://storybook.rsbuild.rs/guide/framework/web-components |
| React Native Web | | https://storybook.rsbuild.rs/guide/framework/react-native-web |
从应用依赖项(、、等)推断UI框架:
reactvuelit| UI框架 | 框架包名称 | 指南 |
|---|---|---|
| React | | https://storybook.rsbuild.rs/guide/framework/react |
| Vue 3 | | https://storybook.rsbuild.rs/guide/framework/vue |
| Vanilla JS/TS | | https://storybook.rsbuild.rs/guide/framework/vanilla |
| Web Components | | https://storybook.rsbuild.rs/guide/framework/web-components |
| React Native Web | | https://storybook.rsbuild.rs/guide/framework/react-native-web |
3. Set up Storybook
3. 搭建Storybook
- In monorepos, operate in the package that will host stories
- Read and follow the framework guide matched above; install the latest stable major and the matching
storybookmajor (Principle 2)storybook-<framework>-rsbuild - Add to
@rsbuild/coredirectly, alongsidedevDependencies(Principle 3)storybook-<framework>-rsbuild - Ensure uses the correct
.storybook/main.*framework: '<storybook-*-rsbuild>' - Ensure has
package.jsonandstorybook devscriptsstorybook build - If no story file exists yet, scaffold at least one minimal example story (e.g. ) so Verification step 2 has something to render
src/stories/Example.stories.* - Run Verification below
- 在单体仓库中,在托管故事的包目录下操作
- 阅读并遵循上述匹配的框架指南;安装最新稳定版的主版本以及匹配的
storybook主版本(原则2)storybook-<framework>-rsbuild - 将直接添加到
@rsbuild/core中,与devDependencies并列(原则3)storybook-<framework>-rsbuild - 确保使用正确的
.storybook/main.*配置framework: '<storybook-*-rsbuild>' - 确保包含
package.json和storybook dev脚本storybook build - 若尚未存在故事文件,至少生成一个最小示例故事(例如),以便验证步骤2有内容可渲染
src/stories/Example.stories.* - 执行下方的验证
Migration Workflow
迁移流程
Read the upstream migration guide: https://storybook.rsbuild.rs/guide/migration
Follow these steps in order:
- Detect migration type — read (
.storybook/main.*field and/orframework) andcore.builderdependencies to classify as "from webpack5" or "from Vite", then select the matching section in the migration guidepackage.json - Resolve version compatibility — read the "Version compatibility" section in the migration guide, select the correct major based on installed Storybook version
storybook-rsbuild - Replace packages — apply the install/remove mapping from the migration guide using the project's package manager (detect from lockfile); only change packages required by the migration. Always add as a direct devDep alongside the new framework package (Principle 3). Do not remove the old framework package or old devDeps yet — that happens after Verification (Principle 4)
@rsbuild/core - Update — apply the config changes exactly as shown in the migration guide for the detected framework
.storybook/main.* - Migrate custom builder hooks — search for legacy builder hooks (/
webpackFinal); if found, convert following the upstream configuration guide (https://storybook.rsbuild.rs/guide/configuration)viteFinal - Handle addon compatibility — keep addons unchanged initially. If a webpack-only addon must change, route it through for upstream auto-translation, or replace it with the Rsbuild-native equivalent — never silently drop it (Principle 5). Consult the migration guide's addon section for the recommended fix
webpackAddons - Verify, then clean up — both required — run Verification below; once it passes, in the same task complete all of the following before reporting done (Principle 4):
- Remove the old framework package from devDependencies (e.g.
package.json,@storybook/react-webpack5,@storybook/vue3-webpack5,@storybook/react-vite,@storybook/vue3-vite,@storybook/html-webpack5, etc.)@storybook/web-components-webpack5 - Remove the old builder package if separately listed (e.g. ,
@storybook/builder-webpack5)@storybook/builder-vite - Delete the legacy /
webpackFinalblock fromviteFinal.storybook/main.* - Drop any old-builder-only devDeps that no longer have consumers
- Re-run (or the project's package manager equivalent) so the lockfile reflects the cleanup
pnpm install
- Remove the old framework package from
If a factual mapping is needed (version table, package names, conversion patterns) and not present in this skill, fetch it from the upstream docs — do not guess.
按以下顺序执行步骤:
- 检测迁移类型 — 读取(
.storybook/main.*字段和/或framework)和core.builder依赖项,分类为“从webpack5迁移”或“从Vite迁移”,然后选择迁移指南中对应的章节package.json - 解决版本兼容性 — 阅读迁移指南中的“Version compatibility”章节,根据已安装的Storybook版本选择正确的主版本
storybook-rsbuild - 替换包 — 使用项目的包管理器(从锁文件检测)应用迁移指南中的安装/移除映射;仅更改迁移所需的包。始终将作为直接开发依赖项添加到新框架包旁(原则3)。暂时不要移除旧框架包或旧开发依赖项——这将在验证完成后进行(原则4)
@rsbuild/core - 更新— 完全按照迁移指南中对应框架的说明应用配置更改
.storybook/main.* - 迁移自定义构建器钩子 — 搜索遗留构建器钩子(/
webpackFinal);若存在,按照上游配置指南(https://storybook.rsbuild.rs/guide/configuration)进行转换viteFinal - 处理插件兼容性 — 初始阶段保持插件不变。若仅支持webpack的插件必须更改,通过传递以进行上游自动转换,或是替换为Rsbuild原生的等效插件——切勿静默移除(原则5)。查阅迁移指南的插件章节获取推荐修复方案
webpackAddons - 验证,然后清理——两者均需完成 — 执行下方的验证;一旦通过,在同一任务中完成以下所有操作后再报告完成(原则4):
- 从的开发依赖项中移除旧框架包(例如
package.json、@storybook/react-webpack5、@storybook/vue3-webpack5、@storybook/react-vite、@storybook/vue3-vite、@storybook/html-webpack5等)@storybook/web-components-webpack5 - 若单独列出了旧构建器包,将其移除(例如、
@storybook/builder-webpack5)@storybook/builder-vite - 从中删除遗留的
.storybook/main.*/webpackFinal代码块viteFinal - 移除所有不再被引用的仅支持旧构建器的开发依赖项
- 重新运行(或项目包管理器的等效命令),使锁文件反映清理后的状态
pnpm install
- 从
若需要事实映射信息(版本表、包名、转换模式)且本指南未提供,请从上游文档获取——切勿猜测。
Verification
验证
- starts without errors
storybook dev - At least one story renders correctly in the browser (a clean dev-server boot is not sufficient — a missing-glob in or a broken framework wiring will only surface here)
stories - HMR works
- completes
storybook build - Check startup logs to confirm the Rsbuild builder is active (not webpack/vite)
- 启动无错误
storybook dev - 至少一个故事在浏览器中正确渲染(仅开发服务器成功启动并不足够——中的glob缺失或框架连接异常只会在此处显现)
stories - HMR(热模块替换)正常工作
- 执行完成
storybook build - 检查启动日志,确认Rsbuild构建器处于激活状态(而非webpack/vite)
Troubleshooting
故障排查
- Cache issues: remove and retry
node_modules/.cache/storybook - Residual config: if dev fails after migration, temporarily remove custom block to isolate the issue, then re-add incrementally
rsbuildFinal - For debugging and other issues, consult the upstream migration guide's "Debugging" section and https://storybook.rsbuild.rs/guide/configuration
- 缓存问题:删除后重试
node_modules/.cache/storybook - 残留配置:若迁移后开发服务器启动失败,临时移除自定义的代码块以隔离问题,然后逐步重新添加
rsbuildFinal - 如需调试或解决其他问题,请查阅上游迁移指南的“Debugging”章节以及https://storybook.rsbuild.rs/guide/configuration
Edge Cases
边缘情况
- Monorepo: locate the package that hosts stories; operate there, not at root
- Multiple dirs: pick the one referenced by
.storybook/scriptspackage.json - TS path aliases: ensure aliases are preserved after migration; consult the upstream configuration guide for how to configure
rsbuildFinal
- 单体仓库:定位托管故事的包;在该包目录下操作,而非根目录
- 多个目录:选择
.storybook/脚本中引用的目录package.json - TS路径别名:确保迁移后别名仍保留;查阅上游配置指南了解如何配置
rsbuildFinal
Configuration
配置
For , builder options, TypeScript, and framework-specific options → read https://storybook.rsbuild.rs/guide/configuration
rsbuildFinal关于、构建器选项、TypeScript和框架特定选项 → 阅读https://storybook.rsbuild.rs/guide/configuration
rsbuildFinal