A Vite plugin that instruments React components to provide visual highlighting and automatic Storybook story generation during development. Hover over components in your running app to see their details and create stories with a single click.
- ๐ Component Highlighting - Visual overlay on React components with configurable colors
- ๐ One-Click Story Generation - Create Storybook stories directly from your running app
- ๐ฏ JSX Props Support - Properly serializes JSX children and nested components
- ๐ Append to Existing Stories - Add new stories to existing story files
- ๐ Smart Imports - Automatically resolves and adds component imports
- ๐๏ธ DevTools Integration - Built-in Vite DevTools Kit dock panel
- ๐ Debug Overlay - Component stats and story coverage when holding Alt
- โก Performance Optimized - Only active in development, tree-shaken in production
- โจ๏ธ Keyboard Shortcuts - Quick toggles and navigation
npm install vite-plugin-experimental-storybook-devtools
# or
pnpm add vite-plugin-experimental-storybook-devtools
# or
yarn add vite-plugin-experimental-storybook-devtoolsThis plugin requires:
vite>= 5.0.0react>= 18.0.0@vitejs/devtools>= 0.1.0
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { DevTools } from '@vitejs/devtools'
import componentHighlighter from 'vite-plugin-experimental-storybook-devtools/react'
export default defineConfig({
plugins: [
react(),
DevTools(),
componentHighlighter(),
],
})npm run devClick the Vite DevTools floating button (usually bottom-right) and select the Component Highlighter tab.
Once the dock is active:
- Hover over any component to see its tooltip
- Click on a component to open the context menu
- Hold Alt to see all components highlighted at once
- Create stories with a single click!
| Mode | Trigger | Description |
|---|---|---|
| Hover | Mouse over | Shows tooltip for single component |
| Highlight All | Hold Alt |
Shows all components with debug overlay |
| Toggle Sticky | Shift + H |
Keeps highlight-all mode active |
| Dismiss | Escape |
Closes context menu or selection |
- ๐ต Blue - Non-hovered components (when Alt is held)
- ๐ฉท Pink Solid - Currently hovered component
- ๐ฉท Pink Dashed - Other instances of the same component
- ๐ฉท Pink (20% bg) - Selected component
- Click on a highlighted component to open the context menu
- Enter a story name (auto-suggested based on props)
- Click "Create Story" (or "Add Story" if stories exist)
- The story file is created/updated automatically!
- Component name with Storybook icon (if stories exist)
- Relative file path for quick reference
- Props display with current values
- Story name input with smart suggestions
- Open Component - Opens the component file in your editor
- Open Stories - Opens the story file in your editor
- Create/Add Story - Generates story with current props
componentHighlighter({
// Glob patterns for files to instrument (default: framework's extensions)
include: ['**/*.{tsx,jsx}'],
// Glob patterns to exclude
exclude: ['**/node_modules/**', '**/dist/**', '**/*.stories.{tsx,jsx}'],
// Custom event name for story creation
eventName: 'component-highlighter:create-story',
// Enable/disable overlay (default: true)
enableOverlay: true,
// Custom DevTools dock ID
devtoolsDockId: 'component-highlighter',
// Force instrumentation in production (default: false)
force: false,
})The following patterns are excluded by default:
**/node_modules/****/dist/****/*.d.ts**/*.stories.{tsx,jsx,ts,js}**/*.test.{tsx,jsx,ts,js}**/*.spec.{tsx,jsx,ts,js}
The plugin generates TypeScript stories compatible with Storybook 7+:
import React from 'react';
import type { Meta, StoryObj } from '@storybook/react-vite';
import { fn } from 'storybook/test';
import MyButton from './MyButton';
import Icon from './Icon';
const meta = {
title: 'Components/MyButton',
component: MyButton,
} satisfies Meta<typeof MyButton>;
export default meta;
type Story = StoryObj<typeof meta>;
export const Primary: Story = {
args: {
variant: 'primary',
label: 'Click me',
icon: <Icon name="star" />,
onClick: fn(),
},
};| Type | Example | Generated Code |
|---|---|---|
| Primitives | "hello", 42, true |
"hello", 42, true |
| Objects | { nested: { value: 1 } } |
{ nested: { value: 1 } } |
| Arrays | [1, 2, 3] |
[1, 2, 3] |
| JSX Elements | <Icon /> |
<Icon /> (with import) |
| JSX Children | <>Hello <Button /></> |
<>Hello <Button /></> |
| Functions | onClick={handleClick} |
fn() (with import) |
When holding Alt, a debug overlay appears in the top-right corner showing:
- Total components - Number of component instances on screen
- Unique components - Number of distinct component types
- With stories - Components that have story files
- Coverage % - Percentage of components with stories
For detailed technical documentation, see docs/ARCHITECTURE.md.
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ Vite Plugin โ โ Runtime Module โ โ DevTools Dock โ
โ โ โ โ โ โ
โ โข Transform JSX โโโโโถโ โข Runtime HOC โโโโโถโ โข Component UI โ
โ โข Inject meta โ โ โข Registry โ โ โข RPC Handler โ
โ โข Load FW gen โ โ โข Serialization โ โ โข Story create โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
โ Shared Helpers โ โ Framework Story Gen โ
โ โข DOM tracking โ โ โข React generator โ
โ โข Observers โ โ โข Vue generator โ
โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ
- Build-time: Babel/compiler transforms wrap components with framework-specific HOC
- Runtime: HOC registers component instances with metadata and props
- Interaction: Overlay detects mouse events and renders highlights
- Story Creation: Plugin dynamically loads framework-specific story generator, serialized props are sent via RPC, story files are written to disk with framework-specific imports and file extensions
# Clone the repository
git clone https://github.com/your-org/vite-plugin-experimental-storybook-devtools.git
cd vite-plugin-experimental-storybook-devtools
# Install dependencies
pnpm install# Run the playground app
pnpm play
# Run unit tests
pnpm test
# Run E2E tests (requires playground running)
pnpm exec playwright test
# Build the library
pnpm build
# Type check
pnpm typecheckโโโ src/
โ โโโ index.ts # Package entry
โ โโโ create-component-highlighter-plugin.ts # Main Vite plugin
โ โโโ runtime-helpers.ts # Shared runtime utilities
โ โโโ frameworks/
โ โ โโโ types.ts # Shared framework interfaces
โ โ โโโ react/
โ โ โ โโโ index.ts # React framework config
โ โ โ โโโ plugin.ts # React entry point
โ โ โ โโโ transform.ts # Babel AST transformation
โ โ โ โโโ runtime-module.ts # Runtime HOC (React)
โ โ โ โโโ story-generator.ts # React story generation
โ โ โโโ vue/
โ โ โโโ index.ts # Vue framework config
โ โ โโโ plugin.ts # Vue entry point
โ โ โโโ transform.ts # Vue SFC transformation
โ โ โโโ runtime-module.ts # Runtime wrapper (Vue)
โ โ โโโ story-generator.ts # Vue story generation
โ โโโ client/
โ โ โโโ overlay.ts # UI overlay
โ โ โโโ listeners.ts # Event handlers
โ โ โโโ vite-devtools.ts # DevTools dock
โ โโโ utils/
โ โโโ story-generator.ts # Shared story utilities
โ โโโ provider-analyzer.ts # Provider detection
โโโ tests/ # Unit tests
โโโ e2e/ # E2E tests
โโโ playground/ # Development apps
โโโ react/ # React test app
โโโ vue/ # Vue test app
- React & Vue - Currently supports React and Vue (other frameworks coming soon)
- Development only - Disabled in production builds by default
- Vite DevTools required - Needs
@vitejs/devtoolsfor full functionality - Provider dependencies - Components requiring context providers may need Storybook decorators
If your components use context providers (Redux, Router, Theme, etc.), you'll need to set up decorators in your Storybook preview file. The plugin includes a provider analyzer that can help identify these dependencies.
See the Provider Analysis section for more details.
- Vue support
- Svelte support
- Angular support
- Automatic decorator generation
- Component usage analytics
Contributions are welcome! Please read our Contributing Guide before submitting a PR.
When reporting issues, please include:
- Node.js version
- Vite version
- React version
- Browser and version
- Minimal reproduction
MIT ยฉ Yann Braga
The plugin includes a provider analyzer (src/provider-analyzer.ts) that can detect common provider dependencies:
Supported Providers:
- Redux (
react-redux,@reduxjs/toolkit) - React Router (
react-router-dom) - Emotion (
@emotion/react) - Styled Components (
styled-components) - TanStack Query (
@tanstack/react-query) - React Intl (
react-intl) - i18next (
react-i18next) - Chakra UI (
@chakra-ui/react) - Mantine (
@mantine/core) - Next.js (
next/router,next/navigation)
The analyzer scans your app entry point and logs detected providers with decorator suggestions.
| Shortcut | Action |
|---|---|
Alt (hold) |
Show all component highlights + debug overlay |
Shift + H |
Toggle sticky highlight-all mode |
Escape |
Dismiss context menu / clear selection |
- Ensure the DevTools dock is open and the Component Highlighter tab is active
- Check the browser console for errors
- Verify the output path is writable
- Ensure the file matches the
includepatterns - Check that it's not matching an
excludepattern - Verify the component is a function component (not a class)
This typically means the component rendered before the plugin fully loaded. Try refreshing the page.