Storybook for web-components
Storybook for web-components is a UI development environment for your plain web-component snippets.
With it, you can visualize different states of your UI components and develop them interactively.

Storybook runs outside of your app.
So you can develop UI components in isolation without worrying about app specific dependencies and requirements.
Getting Started
cd my-app
npx storybook init -t web_components
For more information visit: storybook.js.org
Storybook also comes with a lot of addons and a great API to customize as you wish.
You can also build a static version of your storybook and deploy it anywhere you want.
Hot Module Reloading (HMR)
As web components register on a global registry which only accepts a certain name/class once it can lead to errors when using classical HMR. There are ideas on how to archive HMR with a static registry but there is no proven solution yet. Therefore the best approach for now is to do full page reloads. If you keep your stories to specific states of components (which we would recommend anyways) this usually means it is fast.
Setup es6/7 dependencies
By default storybook only works with precompiled ES5 code but as most web components themselves and their libs are distributed as ES2017 you will need to manually mark those packages as "needs transpilation".
For example if you have a library called my-library
which is in ES2017 then you can add it like so
module.exports = {
webpackFinal: async (config) => {
const webComponentsRule = config.module.rules.find(
(rule) => rule.use && rule.use.options && rule.use.options.babelrc === false
);
webComponentsRule.test.push(new RegExp(`node_modules(\\/|\\\\)my-library(.*)\\.js$`));
return config;
},
};
By default the following folders are included
src/*.js
packages/*/src/*.js
node_modules/lit-html/*.js
node_modules/lit-element/*.js
node_modules/@open-wc/*.js
node_modules/@polymer/*.js
node_modules/@vaadin/*.js
As you can see the src
folder is also included.
The reason for that is as it has some extra configuration to allow for example import.meta
.
If you use a different folder you will need to make sure webpack/babel can handle it.
FAQ
- While working on my component I get the error
Failed to execute 'define' on 'CustomElementRegistry': the name "..." has already been used with this registry
=> please see Setup page reload via HMR
7.0.0-beta.0 (December 8, 2022)
We made it to beta, folks! 🎉
SB7 overhauls our build architecture, modernizes our output to ESM only, promotes Vite to a first-class peer to Webpack, rethinks our Docs addon, cleans up the UI, and contains hundreds of improvements at every level of the stack. We've been sharing some of these changes on the Storybook blog and will share more over the coming weeks.
Beta means that we don't have any more major changes on the radar for 7.0 and it's mostly stabilization from here on out. The core team is doing some basic testing now, and once we have a good QA plan, we'd love your help to make that happen. Please keep an eye out on the blog and on our Twitter or Mastadon (coming soon!) or Discord if you're interested in helping.
Bug Fixes
- Extend Angular Zone.js peer dependency range #20107
- Vite: Fix static source handling for addon-docs #20147
- Controls: Arrow keys don't work on number controls #19954