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 automatic story discovery, rocketstories integration via a custom Vite plugin, and curated addon presets.
Installation
npm install @vitus-labs/tools-storybookPeer dependencies: react >= 19, react-dom >= 19
For React Native projects, also install: react-native >= 0.74, react-native-web >= 0.19
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"
}
}Storybook Config Files
Create a .storybook/ directory with these files:
// .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
export { default } from '@vitus-labs/tools-storybook/storybook/manager'Auto-Discovery System
Components are automatically discovered and turned into stories without writing manual .stories.tsx files. The indexer scans for component files and generates virtual story modules.
Rocketstyle Components
Get stories with dimension exports (states, sizes, variants) and pseudo-state rendering:
// Automatically discovered from component's index.ts
// Generates stories for each dimension: states, sizes, variantsPlain React Components
Get a basic story with title and default render.
Manual Stories
Standard .stories.tsx files are also discovered normally. The CSF indexer is wrapped to skip rocketstories-generated files to avoid conflicts.
src/
├── Button/
│ ├── index.ts ← Auto-discovered
│ └── Button.stories.tsx ← Manual story (also works)
└── Input/
└── index.ts ← Auto-discoveredFrameworks
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, an esbuild plugin mocks next/font during Vite's dependency pre-bundling. 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 |
Built-in Storybook 10 essentials (actions, backgrounds, controls, measure, outline, toolbars, viewport) are included in core — no config needed.
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)'],
rocketstories: {
module: '@my-org/rocketstories',
export: 'storyOf',
},
addons: {
docs: true,
a11y: true,
chromatic: true,
themes: true,
vitest: true,
},
globals: {},
ui: { theme: 'dark' },
},
}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 utilities (CONFIG, types) |
@vitus-labs/tools-storybook/storybook/main | Storybook main config |
@vitus-labs/tools-storybook/storybook/preview | Storybook preview config |
@vitus-labs/tools-storybook/storybook/manager | Storybook manager config |