Skip to Content
vitus·labs
Tools Storybook

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-storybook

Requirements

  • Node.js >= 22
  • Peer dependencies: react >= 19, react-dom >= 19
  • React Native (optional): react-native >= 0.74, react-native-web >= 0.19 — only needed with framework: '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 enable autoDiscovery

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"
  }
}
CommandModeStories globs
vl_storiesDev server on port (default 6006)storiesDir
vl_stories-buildStatic build into outDir (default /docs)storiesDir
vl_stories-monorepoDev servermonorepoStoriesDir (/packages/*/src/**)
vl_stories-monorepo-buildStatic buildmonorepoStoriesDir

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:

FileTitle
packages/ui-base/src/Badge/__stories__/Badge.stories.tsxui-base/Badge
packages/ui-base/src/Badge/__stories__/Composite.stories.tsxui-base/Badge/Composite
src/__stories__/Element.stories.tsxElement

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 a Default story, one story per dimension (States, Sizes, Variants, Multiples) and a PseudoStates story rendering normal / hover / focus / active / disabled side by side
  • Plain React components get a Default story 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-vite
  • next — uses @storybook/nextjs-vite with next/font mocking
  • react-native — uses @storybook/react-vite with react-native-web aliasing and platform-specific extension resolution

React Native Framework

When framework: 'react-native' is set:

  • Aliases react-native imports to react-native-web so RN components render in the browser
  • Resolves .native.* extensions first (.native.tsx, .native.ts, .native.jsx, .native.js)
  • Sets __NATIVE__ to true and __WEB__ to false

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:

Globalvite / nextreact-native
__BROWSER__truetrue
__WEB__truefalse
__NATIVE__falsetrue
__NODE__falsefalse
__CLIENT__truetrue

Included Addons

Addons are configured via the addons config key. External addons map:

Config KeyAddon Package
a11y@storybook/addon-a11y
chromatic@chromatic-com/storybook
designs@storybook/addon-designs
docs@storybook/addon-docs
mode@vueless/storybook-dark-mode
pseudoStatesstorybook-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
  },
}
OptionDefaultDescription
framework'vite''vite', 'next' or 'react-native'
port6006Dev 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
autoDiscoveryfalseGenerate 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
addonssee API referenceAddon toggles and addon parameters
rocketstoriessee belowModule used by auto-discovered rocketstyle stories

Rocketstories Config

OptionDefaultDescription
module@vitus-labs/rocketstoriesThe npm module to import rocketstories from
exportrocketstoriesThe 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

ExportDescription
@vitus-labs/tools-storybookCONFIG (resolved stories config), TS_CONFIG, types StoriesConfig, VLToolsConfig
@vitus-labs/tools-storybook/storybookstorybookStandalone, storybookBuild — the options objects the CLI passes to Storybook
@vitus-labs/tools-storybook/storybook/mainStorybook main config (default export)
@vitus-labs/tools-storybook/storybook/previewStorybook preview config (default export)
@vitus-labs/tools-storybook/storybook/managerManager theme setup (side-effect module)
Edit on GitHub

Last updated on

On this page