For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /guide/configuration.md.
close

Configuration

Storybook Rsbuild provides several ways to customize the build process and behavior. This guide covers the configuration options available in your .storybook/main.ts.

Storybook Documentation

This guide focuses on Rsbuild-specific configurations. For general Storybook configuration (stories, addons, refs, etc.), please refer to the Storybook Configure documentation.

rsbuildFinal

The rsbuildFinal field gives you direct access to the Rsbuild configuration. You can use it to customize the build config, similar to webpackFinal in the Webpack builder.

This function receives the current Rsbuild config and an options object, and should return the modified config.

Use

mergeRsbuildConfig for modifications Always use mergeRsbuildConfig from @rsbuild/core to modify the config in rsbuildFinal; returning a brand-new config is unsupported. Directly replacing properties like config.tools.rspack = {...} may also be silently ignored because internal configs can be arrays of functions and objects. Inside the function form of tools.rspack, modify and return the provided config or use the callback's mergeConfig utility; returning a brand-new object silently drops Storybook-injected wiring such as the sb.mock machinery.

.storybook/main.ts
import type { 
import StorybookConfig
StorybookConfig
} from 'storybook-react-rsbuild'
import {
import mergeRsbuildConfig
mergeRsbuildConfig
} from '@rsbuild/core'
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: never[]
addons
: [],
async
function rsbuildFinal(config: any, { configType }: {
    configType: any;
}): Promise<any>
rsbuildFinal
(
config: any
config
, {
configType: any
configType
}) {
// Customize Rsbuild config here if (
configType: any
configType
=== 'PRODUCTION') {
return
import mergeRsbuildConfig
mergeRsbuildConfig
(
config: any
config
, {
performance: {
    removeConsole: boolean;
}
performance
: {
removeConsole: boolean
removeConsole
: true,
}, }) } // Example: add resolve alias return
import mergeRsbuildConfig
mergeRsbuildConfig
(
config: any
config
, {
resolve: {
    alias: {
        '@components': string;
    };
}
resolve
: {
alias: {
    '@components': string;
}
alias
: {
'@components': './src/components', }, }, }) }, } export default
const config: StorybookConfig
config

Builder Options

You can configure the underlying Rsbuild builder through the core.builder options.

.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: never[]
stories
: [],
core: {
    builder: {
        name: string;
        options: {
            rsbuildConfigPath: string;
            fsCache: boolean;
        };
    };
}
core
: {
builder: {
    name: string;
    options: {
        rsbuildConfigPath: string;
        fsCache: boolean;
    };
}
builder
: {
name: string
name
: 'storybook-builder-rsbuild',
options: {
    rsbuildConfigPath: string;
    fsCache: boolean;
}
options
: {
// Path to your existing rsbuild.config.ts // Defaults to the root rsbuild.config.ts if found
rsbuildConfigPath: string
rsbuildConfigPath
: './custom-rsbuild.config.ts',
// Enable filesystem cache for faster rebuilds // Default: false
fsCache: boolean
fsCache
: true,
// Lazy-compile entries as well as dynamic imports // lazyCompilation: true, // Specify Rsbuild environment to use (for multi-environment configs) // environment: 'web', }, }, }, } export default
const config: StorybookConfig
config

Inherited Rsbuild Configuration

The config selected by rsbuildConfigPath is automatically merged into the Storybook preview build. Production-only settings can affect or break the preview, so the following fields are not inherited:

  • source.entry
  • output.distPath, output.filename, output.cleanDistPath, output.externals, and output.assetPrefix
  • server.publicDir
  • dev.progressBar, dev.assetPrefix, dev.writeToDisk, and dev.client
  • tools.htmlPlugin
  • tools.rspack.output.library, tools.rspack.output.globalObject, and tools.rspack.output.umdNamedDefine

This boundary also applies to configuration inherited by storybook-addon-rslib, storybook-addon-rstack, and storybook-addon-modernjs. Function-form tools.rspack values are opaque and cannot be stripped. Prefer a dedicated Rsbuild environment selected with environment to isolate Storybook-safe settings. To restore a stripped field intentionally, add it explicitly in Storybook's rsbuildFinal; explicit configuration runs after inherited configuration is stripped.

Plugins remain inherited because they commonly provide transforms required by the preview build. The Storybook CLI sets process.env.STORYBOOK to 'true' before loading project configuration, so use that condition to omit an app-only plugin that should not run in Storybook.

Option Reference

OptionTypeDefaultDescription
rsbuildConfigPathstringcwd/rsbuild.config.tsPath to an existing Rsbuild config file to merge.
fsCachebooleanfalseEnables Rspack's persistent filesystem cache.
lazyCompilationboolean | LazyCompilationOptions{ entries: false } (development); false (production)Configures Rspack's lazy compilation.
environmentstringundefinedSelects an environment from the Rsbuild config; an explicit name must exist.

When environment is omitted, zero environments uses top-level config, one is selected automatically, and multiple environments require a name.

In development, the default { entries: false } compiles entry chunks eagerly while lazily compiling dynamically imported story modules. In production, this builder option is not applied, so lazy compilation remains off by default; lower-level Rsbuild or Rspack configuration can override that behavior. In development, automatic MSW detection also changes the default to false unless you explicitly configure this option. This differs from the Storybook webpack builder, where lazy compilation is opt-in and remains off unless enabled.

Webpack Addons Compatibility

Since Rspack is compatible with the webpack loader/plugin API, you can often use Storybook addons designed for Webpack. To run an addon's webpackFinal, list it in webpackAddons. This is the only place where webpackFinal runs: the webpackFinal of entries in addons is not run, and neither is webpackFinal in .storybook/main.ts (use rsbuildFinal instead).

.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: never[]
stories
: [],
// Addons that depend on Webpack loaders/plugins
webpackAddons: string[]
webpackAddons
: ['@storybook/addon-coverage'],
} export default
const config: StorybookConfig
config

Each addon's webpackFinal runs on the fully composed Rspack config, after the builder's defaults and the webpack preset output, so it can read or replace existing rules, plugins, and resolve options. A tools.rspack hook added in rsbuildFinal still runs after it.

For webpackAddons entries, only webpackFinal is applied. Other preset hooks they export, such as managerEntries or previewAnnotations, are ignored. If an addon also provides UI or other hooks, list it in both addons and webpackAddons.

Framework Options

Framework-specific options allow you to tailor the behavior for React, Vue, etc.

React Options

For storybook-react-rsbuild, you can configure strictMode.

.storybook/main.ts
import type { 
import StorybookConfig
StorybookConfig
} from 'storybook-react-rsbuild'
const
const config: StorybookConfig
config
:
import StorybookConfig
StorybookConfig
= {
framework: {
    name: string;
    options: {
        strictMode: boolean;
    };
}
framework
: {
name: string
name
: 'storybook-react-rsbuild',
options: {
    strictMode: boolean;
}
options
: {
// Configure strict mode
strictMode: boolean
strictMode
: true,
}, },
stories: never[]
stories
: [],
} export default
const config: StorybookConfig
config

Vue Options

For storybook-vue3-rsbuild, framework.options.docgen selects the builder docgen engine for component props, events, slots, and exposes.

.storybook/main.ts
import type { 
import StorybookConfig
StorybookConfig
} from 'storybook-vue3-rsbuild'
const
const config: StorybookConfig
config
:
import StorybookConfig
StorybookConfig
= {
framework: {
    name: string;
    options: {
        docgen: {
            plugin: string;
            tsconfig: string;
        };
    };
}
framework
: {
name: string
name
: 'storybook-vue3-rsbuild',
options: {
    docgen: {
        plugin: string;
        tsconfig: string;
    };
}
options
: {
docgen: {
    plugin: string;
    tsconfig: string;
}
docgen
: {
plugin: string
plugin
: 'vue-component-meta',
tsconfig: string
tsconfig
: 'tsconfig.app.json',
}, }, },
stories: never[]
stories
: [],
} export default
const config: StorybookConfig
config
  • false disables builder docgen.
  • 'vue-docgen-api' (the default) or 'vue-component-meta' picks the engine.
  • { plugin: 'vue-component-meta', tsconfig } passes a tsconfig path, resolved relative to the project root. It defaults to 'tsconfig.json'; set it when your root tsconfig only contains references.

These options are ignored while server-side docgen is on, which is the default.

Web Components Options

For storybook-web-components-rsbuild, framework.options.customElementsManifest points at one or more Custom Elements Manifest files.

.storybook/main.ts
import type { 
import StorybookConfig
StorybookConfig
} from 'storybook-web-components-rsbuild'
const
const config: StorybookConfig
config
:
import StorybookConfig
StorybookConfig
= {
framework: {
    name: string;
    options: {
        customElementsManifest: string;
    };
}
framework
: {
name: string
name
: 'storybook-web-components-rsbuild',
options: {
    customElementsManifest: string;
}
options
: {
customElementsManifest: string
customElementsManifest
: './custom-elements.json',
}, },
stories: never[]
stories
: [],
} export default
const config: StorybookConfig
config

Paths resolve relative to the Storybook config directory. When the option is omitted, Storybook reads the customElements field from the nearest package.json. Tags that no manifest declares are generated from the project sources.

Component docgen

Storybook 11 extracts component metadata on the Storybook server (features.docgenServer). It is on by default for React, Vue, and Web Components. React, Vue, and Web Components need the typescript package installed; it is a required peer dependency of their frameworks. Vanilla HTML has no docgen.

For React, props come from TypeScript types. Default values are taken from inline destructuring defaults first, then Component.defaultProps / static defaultProps, then JSDoc @default / @defaultValue. propTypes is not read.

Builder docgen is deprecated

React's typescript.reactDocgen / typescript.reactDocgenTypescriptOptions and Vue's framework.options.docgen run only when features.docgenServer resolves to false. Leave the flag unset and React or Vue projects without typescript fall back to builder docgen automatically; set features.docgenServer: true explicitly and builder docgen is skipped even without typescript. Both options are deprecated and will be removed in Storybook 12.

To keep builder docgen for now:

.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: never[]
stories
: [],
features: {
    docgenServer: boolean;
}
features
: {
// Opt out of server-side docgen and keep builder docgen
docgenServer: boolean
docgenServer
: false,
},
typescript: {
    reactDocgen: string;
}
typescript
: {
// 'react-docgen-typescript' | 'react-docgen' | false
reactDocgen: string
reactDocgen
: 'react-docgen-typescript',
}, } export default
const config: StorybookConfig
config

TypeScript Options

Storybook Rsbuild uses @rsbuild/plugin-type-check for type checking. You can configure it via the typescript field.

.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: never[]
stories
: [],
typescript: {
    check: boolean;
    checkOptions: {
        typescript: {
            memoryLimit: number;
        };
    };
}
typescript
: {
// Enable/disable fork-ts-checker-webpack-plugin
check: boolean
check
: true,
// Options passed to fork-ts-checker-webpack-plugin
checkOptions: {
    typescript: {
        memoryLimit: number;
    };
}
checkOptions
: {
typescript: {
    memoryLimit: number;
}
typescript
: {
memoryLimit: number
memoryLimit
: 4096,
}, }, }, } export default
const config: StorybookConfig
config

See Storybook TypeScript Docs for general TypeScript configuration.

Preview Output Layout

storybook build emits the preview with a flat layout — bundled JS and CSS land directly in the output directory (storybook-static by default), the same as the official webpack5 builder:

storybook-static/
├── iframe.html
├── main.<hash>.iframe.bundle.js
├── <chunk-id>.<hash>.iframe.bundle.js
├── <entry>.<hash>.css
├── <name>.<hash>.svg      # imported SVGs and WebAssembly also land at the root
└── static/media/          # imported images, fonts, and media

Versions before v3.4.0 nested these files under static/js/, static/js/async/, and static/css/.