Tools Storybook
Preconfigured Storybook 10 setup for React projects with Vite, Next.js, or React Native.
@vitus-labs/tools-storybook provides a preconfigured Storybook 10 setup with rocketstories-aware story indexing, opt-in component auto-discovery, and curated addon presets. The vl_stories* CLI commands run Storybook with the bundled config, so a project needs no .storybook/ directory.
Installation
npm install @vitus-labs/tools-storybookRequirements
- Node.js
>= 22 - Peer dependencies:
react >= 19,react-dom >= 19 - React Native (optional):
react-native >= 0.74,react-native-web >= 0.19— only needed withframework: 'react-native' - Rocketstories (optional): auto-discovered rocketstyle stories import from the configured rocketstories module (default
@vitus-labs/rocketstories), which is not a dependency of this package — install it yourself if you enableautoDiscovery
Storybook 10, Vite 8 and all the addons listed below are regular dependencies and are installed for you.
Quick Start
CLI Commands
Add scripts to your package.json:
{
"scripts": {
"stories": "vl_stories",
"stories:build": "vl_stories-build"
}
}For monorepos:
{
"scripts": {
"stories": "vl_stories-monorepo",
"stories:build": "vl_stories-monorepo-build"
}
}| Command | Mode | Stories globs |
|---|---|---|
vl_stories | Dev server on port (default 6006) | storiesDir |
vl_stories-build | Static build into outDir (default /docs) | storiesDir |
vl_stories-monorepo | Dev server | monorepoStoriesDir (/packages/*/src/**) |
vl_stories-monorepo-build | Static build | monorepoStoriesDir |
The monorepo commands set VL_MONOREPO=1 before the config is loaded, which switches the stories (and auto-discovery) globs to their monorepo* variants. All paths are resolved relative to the current working directory.
Storybook Config Files
The CLI commands point Storybook at the package's own bundled config directory, so no .storybook/ directory is needed to use them. If you prefer to run the storybook CLI directly, create a .storybook/ directory that re-exports the presets:
// .storybook/main.ts
export { default } from '@vitus-labs/tools-storybook/storybook/main'// .storybook/preview.ts
export { default } from '@vitus-labs/tools-storybook/storybook/preview'// .storybook/manager.ts
import '@vitus-labs/tools-storybook/storybook/manager'The manager module has no default export — it applies the manager theme via addons.setConfig() as a side effect, so import it rather than re-exporting.
Stories Indexing
Standard CSF / MDX Stories
Regular *.stories.* files (CSF and MDX) work as usual. The package registers a custom indexer for *.stories.* files that handles rocketstories files itself and delegates every other story file to Storybook's default CSF/MDX indexers, so standard stories are indexed normally.
Rocketstories Files
Story files whose default export is something.init (the rocketstories pattern, e.g. export default stories.init) can't be statically parsed by the CSF indexer. The custom indexer handles them: every export const Name = ... becomes a story, and the title comes from .config({ name: '...' }) if present, otherwise it is derived from the file path:
| File | Title |
|---|---|
packages/ui-base/src/Badge/__stories__/Badge.stories.tsx | ui-base/Badge |
packages/ui-base/src/Badge/__stories__/Composite.stories.tsx | ui-base/Badge/Composite |
src/__stories__/Element.stories.tsx | Element |
Auto-Discovery (opt-in)
With autoDiscovery: true, components are turned into stories without writing manual story files. The autoDiscoveryDir globs (default /src/**/index.@(js|jsx|ts|tsx), or monorepoAutoDiscoveryDir in monorepo mode) are appended to the stories globs, and an extra indexer generates virtual story modules for component index.* files.
- Rocketstyle components (detected by
.config(),.theme(),.states(),.sizes(),.variants(), … calls) get aDefaultstory, one story per dimension (States,Sizes,Variants,Multiples) and aPseudoStatesstory rendering normal / hover / focus / active / disabled side by side - Plain React components get a
Defaultstory rendering the component with args - Components that already have story files in a sibling
__stories__/folder are skipped
src/
├── Button/
│ ├── index.ts ← Skipped (has manual stories)
│ └── __stories__/
│ └── Button.stories.tsx ← Manual story
└── Input/
└── index.ts ← Auto-discovered (autoDiscovery: true)Frameworks
Three framework options are available:
vite(default) — uses@storybook/react-vitenext— uses@storybook/nextjs-vitewithnext/fontmockingreact-native— uses@storybook/react-vitewithreact-native-webaliasing and platform-specific extension resolution
React Native Framework
When framework: 'react-native' is set:
- Aliases
react-nativeimports toreact-native-webso RN components render in the browser - Resolves
.native.*extensions first (.native.tsx,.native.ts,.native.jsx,.native.js) - Sets
__NATIVE__totrueand__WEB__tofalse
For web frameworks (vite, next), .web.* extensions are resolved first instead.
Next.js Framework
When framework: 'next' is set, a plugin added to Vite's dependency pre-bundling (optimizeDeps.rolldownOptions.plugins) mocks next/font/local, next/font/google (and the @next/font/* equivalents), and the preview enables nextjs.appDirectory. This prevents npm font packages (e.g. geist) from baking the real Next.js font module into pre-bundled chunks.
Platform Globals
The Vite config defines platform globals that are available in stories:
| Global | vite / next | react-native |
|---|---|---|
__BROWSER__ | true | true |
__WEB__ | true | false |
__NATIVE__ | false | true |
__NODE__ | false | false |
__CLIENT__ | true | true |
Included Addons
Addons are configured via the addons config key. External addons map:
| Config Key | Addon Package |
|---|---|
a11y | @storybook/addon-a11y |
chromatic | @chromatic-com/storybook |
designs | @storybook/addon-designs |
docs | @storybook/addon-docs |
mode | @vueless/storybook-dark-mode |
pseudoStates | storybook-addon-pseudo-states |
themes | @storybook/addon-themes |
vitest | @storybook/addon-vitest |
An addon is registered when its key is truthy; set a key to false to drop it. All eight are enabled by default.
Built-in Storybook 10 essentials (actions, backgrounds, controls, measure, outline, toolbars, viewport) ship with Storybook core and need no registration. Any addons entry whose value is an object (e.g. controls, viewport, backgrounds, darkMode) is passed to the preview as parameters[key], so you can configure them from the same place.
Backgrounds
addons.backgrounds.default is the key of one of the backgrounds.options entries. Storybook 10 no longer reads parameters.backgrounds.default, so the preview maps it onto the backgrounds initial global ({ backgrounds: { value: default } }). An explicit globals.backgrounds still wins.
Manager Theme
ui.theme ('dark' by default) selects the Storybook manager UI theme. It is passed to the manager bundle as STORYBOOK_VL_UI_THEME and applied with Storybook's themes.dark / themes.light.
Configuration
Configure via vl-tools.config.mjs under the stories key:
export default {
stories: {
framework: 'next', // 'vite' | 'next' | 'react-native'
port: 6006,
outDir: '/docs',
storiesDir: ['/src/**/*.stories.@(js|jsx|ts|tsx|md|mdx)'],
autoDiscovery: false, // true → generate stories from component index files
rocketstories: {
module: '@my-org/rocketstories',
export: 'storyOf',
},
addons: {
docs: true,
a11y: true,
chromatic: false,
backgrounds: {
default: 'dark',
options: {
light: { name: 'Light', value: '#fff' },
dark: { name: 'Dark', value: '#000' },
},
},
},
globals: {},
ui: { theme: 'light' }, // manager UI theme
},
}| Option | Default | Description |
|---|---|---|
framework | 'vite' | 'vite', 'next' or 'react-native' |
port | 6006 | Dev server port (vl_stories*) |
outDir | '/docs' | Static build output, relative to cwd (vl_stories*-build) |
storiesDir | ['/src/**/*.stories.@(js|jsx|ts|tsx|md|mdx)'] | Story globs, relative to cwd |
monorepoStoriesDir | ['/packages/*/src/**/*.stories.@(js|jsx|ts|tsx|md|mdx)'] | Story globs used by the -monorepo commands |
autoDiscovery | false | Generate virtual stories from component index.* files |
autoDiscoveryDir | ['/src/**/index.@(js|jsx|ts|tsx)'] | Component globs used when autoDiscovery is on |
monorepoAutoDiscoveryDir | ['/packages/*/src/**/index.@(js|jsx|ts|tsx)'] | Component globs in monorepo mode |
ui.theme | 'dark' | Manager UI theme: 'dark' or 'light' |
globals | {} | Preview initialGlobals |
addons | see API reference | Addon toggles and addon parameters |
rocketstories | see below | Module used by auto-discovered rocketstyle stories |
Rocketstories Config
| Option | Default | Description |
|---|---|---|
module | @vitus-labs/rocketstories | The npm module to import rocketstories from |
export | rocketstories | The named export to use from the module |
This controls what auto-discovered stories import. When your rocketstories wrapper uses init({ decorators: [ThemeProvider] }), auto-discovered stories automatically get your decorators.
Exports
| Export | Description |
|---|---|
@vitus-labs/tools-storybook | CONFIG (resolved stories config), TS_CONFIG, types StoriesConfig, VLToolsConfig |
@vitus-labs/tools-storybook/storybook | storybookStandalone, storybookBuild — the options objects the CLI passes to Storybook |
@vitus-labs/tools-storybook/storybook/main | Storybook main config (default export) |
@vitus-labs/tools-storybook/storybook/preview | Storybook preview config (default export) |
@vitus-labs/tools-storybook/storybook/manager | Manager theme setup (side-effect module) |
Last updated on