-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Question: Loading stories from individual component folders? #1171
Comments
@reggi like this? https://storybook.js.org/basics/writing-stories/#loading-stories-dynamically Or did you have something else in mind? |
Thanks! |
What if our components are in multiple node module folders? Eg: import { configure } from '@storybook/react';
const req = require.context("@my-lib/src/", true, /.stories.js$/);
const req2 = require.context("@your-lib/src/", true, /.stories.js$/);
// How can I require stories from req2?
configure(() => {
req.keys().forEach(filename => req(filename));
}, module); |
I would also like to know the right way to do this. |
@zlw11063 - I found this kind of thing to work ok... import {configure} from '@storybook/react';
const libs = ['@my-lib/src', '@your-lib/src'];
configure(() => {
libs.map(lib => require.context(lib, true, /.stories.js$/)).forEach(req =>
req.keys().forEach(filename => req(filename))
);
}, module); |
@alistair-hmh don't you get webpack compile errors when using that? |
My variant:
|
Just pass them in as an array:
https://storybook.js.org/docs/basics/writing-stories/#loading-stories-dynamically |
I'm interested in editing my
config.js
to abide by a different storybook structure.Where each storybook story for a given component lives in the same folder with the component itself.
I think this would be a useful config to document for others as well.
The text was updated successfully, but these errors were encountered: