Storybook for React with Webpack
Storybook for React & Webpack is a framework that makes it easy to develop and test UI components in isolation for React applications built with Webpack.
We recommend using @storybook/react-vite for most React projects. The Vite-based framework is faster, more modern, and offers better support for testing features.
Use this Webpack-based framework (@storybook/react-webpack5) only if you need specific Webpack features not available in Vite.
Install
To install Storybook in an existing React project, run this command in your project's root directory:
npm create storybook@latestYou can then get started writing stories, running tests and documenting your components. For more control over the installation process, refer to the installation guide.
Requirements
React ≥ 16.8
Webpack ≥ 5.101
Run Storybook
To run Storybook for a particular project, run the following:
npm run storybookTo build Storybook, run:
npm run build-storybookYou will find the output in the configured outputDir (default is storybook-static).
Configure
Manually initialized apps
If you're working on an app that was initialized manually, ensure that your app has react-dom included as a dependency. Failing to do so can lead to unforeseen issues with Storybook and your project.
Component documentation
Storybook 11 reads React component props on the server by default, with the typescript package (TypeScript 5.9 or 6, even in JavaScript projects, where it reads types from JSDoc comments). New projects need no docgen configuration and no extra packages.
The Storybook 10 builder-based docgen is still available, but it is deprecated. It will be removed in Storybook 12. To use it:
- Set
features.docgenServer: falsein your main config. - Set the package you want to use in
typescript.reactDocgen. The default is'react-docgen'. - Install the packages for that mode in your devDependencies:
typescript.reactDocgen | Packages to install |
|---|---|
'react-docgen' (default) | react-docgen |
'react-docgen-typescript' | @storybook/react-docgen-typescript-plugin@1.0.6--canary.9.0c3f3b7.0 (this exact version; its latest tag is older) and react-docgen-typescript |
When a docgen package is missing, Storybook stops and prints the install command. To run without docgen instead, set typescript.reactDocgen: false.
Projects on TypeScript 7.0 cannot use server-side docgen yet. See TypeScript 7.
FAQ
How do I manually install the React Webpack framework?
First, install the framework:
npm install --save-dev @storybook/react-webpack5Next, install and register your appropriate compiler addon, depending on whether you're using SWC (recommended) or Babel:
npx storybook@latest add @storybook/addon-webpack5-compiler-swcor
npx storybook@latest add @storybook/addon-webpack5-compiler-babelMore details can be found in the Webpack builder docs.
Finally, update your .storybook/main.js|ts to change the framework property:
// Replace your-framework with the framework you are using (e.g., react-vite, nextjs, nextjs-vite)
import { defineMain } from '@storybook/your-framework/node';
export default defineMain({
// ...
framework: '@storybook/react-webpack5', // 👈 Add this
});How do I migrate to the React Vite framework?
Please refer to the migration instructions for @storybook/react-vite.
API
Options
You can pass an options object for additional configuration if needed:
// Replace your-framework with the framework you are using (e.g., react-vite, nextjs, nextjs-vite)
import { defineMain } from '@storybook/your-framework/node';
export default defineMain({
framework: {
name: '@storybook/react-webpack5',
options: {
// ...
},
},
});builder
Type: Record<string, any>
Configure options for the framework's builder. For this framework, available options can be found in the Webpack builder docs.
