How does Storybook work today?
Today, when you run yarn redwood storybook
, there are two important things to be aware of:
- The config used lives in the @redwoodjs/testing package.
- When Storybook was added to Redwood, Framework Packages did not yet exist. Therefore, we had to more tightly couple Storybook within the framework.
- This is in contrast to the default place for Storybook config files, the in-project .storybook directory.
- Storybook is built using Webpack.
- This is simply because, as you may know, Webpack used to be the default bundler.
What is changing, and why?
Vite has been the default bundler for just over a year, and Storybook has been the primary holdout for this migration — until now!
Additionally, now that Storybook supports Framework Packages, we felt this migration was a natural time to move the Storybook config out of the monorepo and into your projects.
This means that you’ll get two primary advantages:
- Storybook is now much faster: Storybook Performance: Vite vs Webpack
- You get full ownership over your Storybook config!
Before you continue, please note:
- Currently, only projects using Typescript are supported.
- If you are still using Webpack, this is not for you, and you should consider switching to Vite
- Unless you’ve got
bundler = "webpack"
in yourredwood.toml
file, you’re using Vite.
How do I upgrade?
Getting started is easy — you’ll first want to make sure you’re on at least v7.7.0, and then run:
yarn redwood storybook-vite
On first run, we’ll create the following config files for you:
web/.storybook/main.ts
- This is the primary Storybook configuration file. Note that it references the brand new framework package,
storybook-framework-redwoodjs-vite
.
- This is the primary Storybook configuration file. Note that it references the brand new framework package,
web/.storybook/preview-body.html
- This is required to change the
id
of the root div toredwood-app
, which is what the entry file used by Vite requires.
- This is required to change the
Previously, we also allowed
unplugin-auto-import
, used by the Framework Package here, to createweb/src/auto-imports.d.ts
. If you’re on an early version, you may still have this, though this has been disabled.
- Thanks @oliwheeler for reminding us to include this here!
Then, as usual, Storybook should open in your browser!
If you don’t have any of your own Storybook configuration, you should be good to go.
If you do have custom Storybook configuration, then you’ll need to manually migrate it over to the new files. For example, if you’ve got any global decorators, you can now just follow the official Storybook docs on that: Docs | Storybook
A note on migrating over
web/config/storybook.preview.js
(or generally working with thepreview
config file):
- You’ll generally use
web/.storybook/preview.{ts/js}
.- However, if you’ve got any JSX in this file, you’ll instead need to use the
{tsx/jsx}
file extension.Thank you @Philzen for calling this out!
And, of course, if you run into any problems or have any questions, we’d love to hear about it.