[RFC] Improve preset API #30149
Replies: 1 comment 1 reply
-
I completely agree with your problem statement, and also with the idea of But I think we should instead draw inspiration from Vite's plugin system and ESLint's recent flat config changes, where the user in their config imports plugins/addons/presets/etc., instead of using a magic name string that Storybook then internally tries to load the best it can. We have lots of issues today with trying to load these string-based presets non-trivial setups like monorepos where the package might not be located where we'd expect, or PnP-based package managers that have their own module loading mechanism we need to hook into. To give an idea of what I mean, instead of this current config: // .storybook/main.js
export default {
addons: ['@storybook/addon-a11y'],
framework: '@storybook-vue/nuxt'
}; I'd propose this:
This doesn't exactly counter your idea, only the part about loading @ndelangen and I briefly experimented with this direction over a year ago and IIRC he was able to make this work even in a backwards compatible way. |
Beta Was this translation helpful? Give feedback.
-
Summary
Suggestions on how to improve the API for presets.
Problem Statement
The current implementation relies on a couple of "magic" constructions such as
preset.js
file at the root (which needs to be in cjs - what if we want to have a module in esm?)viteFinal
andwebpackFinal
- without any natural type support and typos are also only discovered relatively late in the dev cycle.Non-goals
No response
Implementation
Add a
defineStorybookPreset
method that bundles and declares all allowed objects/features of a preset.Proposed API for presets:
And to load the preset, just try to
import
the preset using node/jiti, instead of relying on the specialpreset.js
file.Prior Art
This is essentially a copy of Nuxt's plugin system which works very well in my experience.
Deliverables
No response
Risks
No response
Unresolved Questions
Alternatives considered / Abandoned Ideas
No response
Beta Was this translation helpful? Give feedback.
All reactions