Rslib
storybook-addon-rslib loads Rsbuild configuration from rslib.config.* for a single library entry while stripping library-specific output fields from the Storybook preview build.
Examples: rslib-react-component, rslib-vue3-component, and rslib-react-mf.
Requirements
| Package | Version |
|---|---|
| Node.js | >= 22.12.0 |
@rslib/core | >= 0.22.0 |
@rsbuild/core | ^2.0.0 |
storybook | ^11.0.0 |
Install the matching Storybook Rsbuild framework package alongside these dependencies, such as storybook-react-rsbuild (React) or storybook-vue3-rsbuild (Vue).
Setup
Install @rsbuild/core and storybook-addon-rslib:
Register storybook-addon-rslib in .storybook/main.ts. When customizing options, nest them under options.rslib:
Pass 'storybook-addon-rslib' as a plain string when the defaults (libIndex: 0, auto-detected rslib.config.* in process.cwd()) apply.
Options
Configure the addon under options.rslib:
cwd
- Type:
string - Default:
undefined
Working directory passed to @rslib/core's loadConfig.
configPath
- Type:
string - Default:
undefined
Config file path passed as path to @rslib/core's loadConfig.
libIndex
- Type:
number | false - Default:
0
Index in lib merged over top-level config. Set false to inherit only top-level config.
When lib is omitted or not an array, index 0 resolves to an implicit {}. An explicit empty array (lib: []) or out-of-range libIndex throws an error. Both lib and environments are dropped when converting to an Rsbuild config.
modifyLibConfig
- Type:
(config: LibConfig) => void - Default:
undefined
Experimental: Mutates the selected LibConfig in place before conversion to an Rsbuild config and before incompatible field stripping.
modifyLibRsbuildConfig
- Type:
(config: RsbuildConfig) => void - Default:
undefined
Experimental: Mutates the converted Rsbuild config in place after incompatible fields are stripped and before Storybook merges it, so you can restore stripped fields explicitly for Storybook.
Inherited configuration
Before merging into Storybook, the converted config passes through the Inherited Rsbuild Configuration stripping boundary. You can also use rsbuildFinal to adjust the merged config or check process.env.STORYBOOK in rslib.config.ts to skip library-only plugins.
Vue 3 with unplugin-vue
unplugin-vue does not currently support HMR with Rspack. If your rslib.config.ts uses rsbuild-plugin-unplugin-vue (pluginUnpluginVue()), remove plugin-unplugin-vue and add @rsbuild/plugin-vue in rsbuildFinal:
Module Federation
storybook-addon-rslib loads a regular lib entry (such as libIndex: 0) for your local build transforms; it does not serve format: 'mf' outputs on its own. To consume an Rslib Module Federation entry in stories, run rslib mf-dev alongside Storybook and register @module-federation/storybook-addon/preset with remotes.
See the Rslib Module Federation documentation and the rslib-react-mf example.
Start rslib mf-dev before or alongside storybook dev so the remote manifest at http://localhost:3001/mf/mf-manifest.json is reachable.