You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Recently, Storybook 7 has been released, along with a Storybook builder API.
This API aims at easing the use of a dev server and / or bundler other than the ones already packaged (Webpack & Vite).
Modern Web has released a Web Storybook builder thanks to which we could keep on using the Web Dev Server and Rollup to serve and build our Storybook + upgrade to Storybook 7.
Even if it's still WIP, we want to try and use it to:
benefit from storybook 7:
lazy loading of stories by default for instance,
config files using ESM instead of CJS 🙌.
move away from the opiniated storybook prebuilt (though it's good and we enjoy using it, it would be great to get closer to Storybook "standard" and manager our Storybook Addons directly for instance).
run npm install @storybook/builder-vite@0.4 @storybook/web-components@6 --save-dev to make as if we were using vite & the web components framework.
run npx storybook@latest upgrade.
The upgrade failed: ❌ Failed trying to evaluate .storybook/main.js with the following error: No "exports" main defined in /home/flo/Projects/clever-components/node_modules/@web/dev-server-storybook/package.json
We decided not to go further with this approach and start from scratch.
Since we have uninstalled @web/dev-server-storybook, we have to disable the storybookWdsPlugin() from our WDS plugins,
There seems to be an issue with HMR which I don't understand (didn't search though): Error: Cannot use HMR when web sockets are disabled. => I disabled (commented) the HMR plugin
Issue when generating autodocs for components. Set it to true but should probably set it to tags and update make-story.js + it failed to load because it was relying on tocbot which uses a require even though it's run within the browser? I had to list tocbot in our WDS commonjs plugin.
Issue with our storybookMenuSort function. Storybook sortStory value must be inlined directly within the preview parameters, it cannot be imported from a file or even a local variable:
=> The good news is that we can use the order property to directly pass the menu we want and storybook now sorts it for us. This allows us to remove some of our code so it's good news in the end.
This also fixed the order of the component stories which are now back to the export order.
issue with preview-head.html links to external CSS => this file is merged with another inside a iframe.html file. The builder does not process the preview-head.html with rollup-plugin-html which means that CSS dependencies are not processed (files are not copied to assets + link paths are not updated). I tried many things that didn't work. In the end I used staticDirs as follows:
issue with docs from templates / controllers / mixin => we don't build doc stories like before (and I didn't manage to make it work the old way with the new indexer API). I switched to docs with front matter loaded like other .md stories. The only downside is that they don't have the same icon as the others + they are listed as the last story 😞
issue with the build => I had forgotten to add the commonJS plugin. Should use the common from rollup
issue with enhanceStoriesNames => Storybook autodefines story names based on the export name. If you want to set a custom name, you can use the name property inside a story. Our enhanceStoriesNames relied on storyName (dunno if it was the old way to do this or something I misunderstood). I tried changing storyFn.storyName to storyFn.name but it throws an error saying the name is a readonly property (which makes sense because now we lazy-load stories and build an index).
=> There is another way to achieve what we had before: use renderLabel from the manager to enhance story names.
renderLabel: ({ name, type })=>type==='story' ? enhanceStoryName(name.toLocaleLowerCase()) : name,
the builder still shows warning about md storyfiles even though it's properly handled (thanks to custom indexers). This is a limitation of the builder, we need to open an issue (or even a PR).
Other stuff to test/fix:
staticDirs to serve our brandImage,
a dark vs light theme (logo)
autodocs with tags instead of true
fix enhanced Story names
fix the build (start tweaking rollupFinal)
use common commonjs rollup plugin (preconfigured)
fix autogenerated docs not working when built 😭
fix story order for docs in templates, controllers, etc.
Context
We are currently using Storybook 6.4.9 thanks to the
Storybook prebuilt
package provided by Modern Web.Recently, Storybook 7 has been released, along with a Storybook builder API.
This API aims at easing the use of a dev server and / or bundler other than the ones already packaged (Webpack & Vite).
Modern Web has released a
Web Storybook builder
thanks to which we could keep on using the Web Dev Server and Rollup to serve and build our Storybook + upgrade to Storybook 7.Even if it's still WIP, we want to try and use it to:
What we've done so far (success & issues)
Using the Storybook migration tool
npm install @storybook/builder-vite@0.4 @storybook/web-components@6 --save-dev
to make as if we were using vite & the web components framework.npx storybook@latest upgrade
.The upgrade failed:
❌ Failed trying to evaluate .storybook/main.js with the following error: No "exports" main defined in /home/flo/Projects/clever-components/node_modules/@web/dev-server-storybook/package.json
We decided not to go further with this approach and start from scratch.
Going for a fresh install
@web/dev-server-storybook
package,.storybook
folder containing our config,storybook cli
as advised in the Storybook Builder: Configuration - Modern Web@web/dev-server-storybook
, we have to disable thestorybookWdsPlugin()
from our WDS plugins,Error: Cannot use HMR when web sockets are disabled.
=> I disabled (commented) the HMR pluginmanager.js
file. Instead ofimport { ... } from '@web/storybook-prebuilt/....js'
=>import { ... } from '@storybook/....js
experimental_indexers
API: [RFC] Indexer API storybookjs/storybook#23176 + by adapting ourmarkdown.cjs
to a WDS plugin.true
but should probably set it totags
and updatemake-story.js
+ it failed to load because it was relying ontocbot
which uses arequire
even though it's run within the browser? I had to listtocbot
in our WDScommonjs
plugin.storybookMenuSort
function. StorybooksortStory
value must be inlined directly within the preview parameters, it cannot be imported from a file or even a local variable:=> The good news is that we can use the
order
property to directly pass the menu we want and storybook now sorts it for us. This allows us to remove some of our code so it's good news in the end.This also fixed the order of the component stories which are now back to the export order.
preview-head.html
links to external CSS => this file is merged with another inside aiframe.html
file. The builder does not process thepreview-head.html
withrollup-plugin-html
which means that CSS dependencies are not processed (files are not copied to assets + link paths are not updated). I tried many things that didn't work. In the end I usedstaticDirs
as follows:templates
/controllers
/mixin
=> we don't build doc stories like before (and I didn't manage to make it work the old way with the new indexer API). I switched to docs with front matter loaded like other.md
stories. The only downside is that they don't have the same icon as the others + they are listed as the last story 😞commonJS
plugin. Should use thecommon
from rollupenhanceStoriesNames
=> Storybook autodefines story names based on the export name. If you want to set a custom name, you can use thename
property inside a story. OurenhanceStoriesNames
relied onstoryName
(dunno if it was the old way to do this or something I misunderstood). I tried changingstoryFn.storyName
tostoryFn.name
but it throws an error saying thename
is a readonly property (which makes sense because now we lazy-load stories and build an index).=> There is another way to achieve what we had before: use
renderLabel
from themanager
to enhance story names.md
storyfiles even though it's properly handled (thanks to custom indexers). This is a limitation of the builder, we need to open an issue (or even a PR).Other stuff to test/fix:
staticDirs
to serve ourbrandImage
,tags
instead oftrue
rollupFinal
)common
commonjs rollup plugin (preconfigured)templates
,controllers
, etc.refs
in config, could it be useful for us?The text was updated successfully, but these errors were encountered: