For AI agents: the complete documentation index is available at https://storybook.rsbuild.rs/llms.txt, the full documentation bundle is available at https://storybook.rsbuild.rs/llms-full.txt, and this page is available as Markdown at https://storybook.rsbuild.rs/guide/integrations/rslib.md.
close

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

PackageVersion
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:

npm
yarn
pnpm
bun
deno
npm install @rsbuild/core storybook-addon-rslib -D

Register storybook-addon-rslib in .storybook/main.ts. When customizing options, nest them under options.rslib:

.storybook/main.ts
import type { 
import StorybookConfig
StorybookConfig
} from 'storybook-react-rsbuild'
const
const config: StorybookConfig
config
:
import StorybookConfig
StorybookConfig
= {
framework: string
framework
: 'storybook-react-rsbuild',
stories: string[]
stories
: ['../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: {
    name: string;
    options: {
        rslib: {
            configPath: string;
            libIndex: number;
        };
    };
}[]
addons
: [
{
name: string
name
: 'storybook-addon-rslib',
options: {
    rslib: {
        configPath: string;
        libIndex: number;
    };
}
options
: {
rslib: {
    configPath: string;
    libIndex: number;
}
rslib
: {
configPath: string
configPath
: './rslib.config.ts',
libIndex: number
libIndex
: 0,
}, }, }, ], } export default
const config: StorybookConfig
config

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:

.storybook/main.ts
import { 
import mergeRsbuildConfig
mergeRsbuildConfig
} from '@rsbuild/core'
import {
import pluginVue
pluginVue
} from '@rsbuild/plugin-vue'
import type {
import StorybookConfig
StorybookConfig
} from 'storybook-vue3-rsbuild'
const
const config: StorybookConfig
config
:
import StorybookConfig
StorybookConfig
= {
framework: string
framework
: 'storybook-vue3-rsbuild',
stories: string[]
stories
: ['../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: string[]
addons
: ['storybook-addon-rslib'],
rsbuildFinal: (config: any) => any
rsbuildFinal
: (
config: any
config
) => {
const
const filteredPlugins: any
filteredPlugins
= (
config: any
config
.plugins ?? []).filter((
plugin: any
plugin
) => {
if (
plugin: any
plugin
&& 'name' in
plugin: any
plugin
) {
return
plugin: any
plugin
.name !== 'plugin-unplugin-vue'
} return true }) return
import mergeRsbuildConfig
mergeRsbuildConfig
(
{ ...
config: any
config
,
plugins: any
plugins
:
const filteredPlugins: any
filteredPlugins
},
{
plugins: any[]
plugins
: [
import pluginVue
pluginVue
()],
}, ) }, } export default
const config: StorybookConfig
config

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.

.storybook/main.ts
import type { 
import StorybookConfig
StorybookConfig
} from 'storybook-react-rsbuild'
const
const config: StorybookConfig
config
:
import StorybookConfig
StorybookConfig
= {
framework: string
framework
: 'storybook-react-rsbuild',
stories: string[]
stories
: ['../stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: (string | {
    name: string;
    options: {
        remotes: {
            'rslib-module': string;
        };
    };
})[]
addons
: [
'storybook-addon-rslib', {
name: string
name
: '@module-federation/storybook-addon/preset',
options: {
    remotes: {
        'rslib-module': string;
    };
}
options
: {
remotes: {
    'rslib-module': string;
}
remotes
: {
'rslib-module': 'rslib-module@http://localhost:3001/mf/mf-manifest.json', }, }, }, ], } export default
const config: StorybookConfig
config

Start rslib mf-dev before or alongside storybook dev so the remote manifest at http://localhost:3001/mf/mf-manifest.json is reachable.