-
-
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
How to use existing build process and use storybook as lib #5975
Comments
Hi @rolandjohann! This is something that we've considered in the past:
I think this is something that @shilman might be thinking about as he starts to think about docs mode; not guaranteed to happen but there might be some related refactoring that makes it much easier to do. Perhaps it makes sense to leave this ticket open to track the idea? |
There's also a node API by @igor-dv , which hasn't been documented and which I'd like to change:
|
Hi together, thanks for quick reply. @tmeasday thanks for pointing to existing issues. Doing the discussion at this ticket makes sense. @shilman I played with that API already which triggers webpack anyway. It seems that the code for build and the actual business logic of storybook is not encapsulated in a way to just use storybook. Are there any detailed plans yet to refactor this and where I can help? |
Hi @rolandjohann -- no plans that I know of? Maybe @ndelangen can weigh in here? I'd be open to some refactoring if it can also simplify the default webpack build process AND make it more debuggable. Every time we change anything related to webpack/babel it generates TONS of issues, so I'm hesitant to make changes here unless they are both well-justified and well-tested. |
Maybe a solution would be to try to externalize a render api that takes an |
Hey all, I've been experiementing / thinking about this a little. I think there are three things here. We can probably achieve all of this of this quite easily and potentially even as part of 5.1 if someone has some time to do some of it. 1. Allow arbitrary preview URLWe should add a new CLI option to It probably wouldn't be too hard to pass it into the manager ( If someone sets such a URL we should also not start the preview webpack process or require a 2. Allowing
|
Number 2 would probably be one of the most flexible solution. Just adding some documentation and examples and people could use what ever build process or bundler they want with Storybook (parcel, fusebox, etc) What kind of HTML do you need for number 2 to work and for the storybook UI to render properly ?
can that be bypassed ? |
Hi @RPDeshaies -- these aren't either/ors -- both 1&2 would be required in the simplest case. It's a good question about HTML. All the storybook view layers (
yes, definitely. Arguably this is just a bug in storybook. Don't even worry about this bit, I just noted it here in case someone runs across it. |
@tmeasday so if someone would want to use storybook with any bundler they would only need to have
import { configure, storiesOf } from "@storybook/react";
import React from "react";
configure(() => {
storiesOf("Category 1").add("Test 1", () => <div>Category 1 - Test 1</div>);
storiesOf("Category 2")
.add("Test 1", () => <div>Category 2 - Test 1</div>)
.add("Test 2", () => <div>Category 2 - Test 2</div>);
}, {}); Right ? So right now, I've done that (with ParcelJS) but the HTML only renders my story and not the whole storybook UI Any ideas why ? I'm probably missing something simple, but once I can make that work, I could make an example repo that you guys could include in the doc to use StorybookJS with ParcelJS |
@RPDeshaies does the above work, e.g. if you browse to To make it really work we'd still need to do part (1), which would allow the storybook UI to run and point at that. So the way you would use it would be to start your app as normal (including the part that renders the stories as above) and also start Storybook pointing at your app. Also I suspect the above code snippet will interact badly with the rest of your app (overwriting routes etc possibly), and we probably want to do part (2) to contain the storybook behaviour in your app to a single route. Are you interested in working on this? I can help out if you want to have a go at it! |
This url works for example: and loads the right story
I personally think its fine as I think storybook should be rendered in its own app. That, at least, could be an easy MVP For example, I've been using React cosmos for months now and I have a very custom build to use it with parcel but when I use it, it's never executed inside the same app context as the rest of my app. It just uses a similar bundling pattern
Maybe ? I dont know anything about the project so I would need some guiding if you have some time |
That's true, that could be a first step.
If you have the time to experiment I can definitely point you in the right direction. What we need to do is:
Happy to have a chat about this if you want to have a go once you've taken a look around. |
Alright maybe I don't understand what you want clearly because I thought the goal was to Wouldn't we just need to export the If the goal is to use an existing build process, I don't think updating webpack would help us doing that no ? |
Sorry if it is unclear. Storybook consists of two parts:
Right now Storybook starts a webpack process for both parts and embeds the preview inside an iframe in the manager (via the What I am proposing is to continue to run the manager via webpack and Storybook's webpack config (this is our code unless you are writing addons). The tricky part is running your own code in the preview inside webpack if you don't use webpack. So instead, you'll run the preview part of storybook yourself, either in a route inside your own app, or in its own app using which ever build tool you like (as you say). |
Gotcha. I'll dig inside the code and will come back with either a solution and or questions |
Questions Should I branch off I as able to add the CLI config for the preview Do you think it's OK if I reuse it to make sure the preview mode is disabled when my flag is also passed ? e.g. // lib/core/src/server/build-dev.js
export async function buildDev({ packageJson, ...loadOptions }) {
const cliOptions = await getDevCli(packageJson);
const hasPreviewUrlCliOption = !!cliOptions.previewUrl;
await buildDevStandalone({
...cliOptions,
...loadOptions,
packageJson,
configDir: loadOptions.configDir || cliOptions.configDir || './.storybook',
// IMPORTANT PART 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇 👇
ignorePreview: loadOptions.ignorePreview || hasPreviewUrlCliOption,
});
} I found multiple places where
And that is pretty much it. Though even though I'm trying to debug/log I don't seem to be able to find where it's ACTUALLY used by the HTML to load the iframe. Maybe I'm missing something According to the doc, you need to run
Is there a way to accomplish that ? My computer's RAM and CPU you thank you very much |
Branch off
Seems great, yeah! (Someone else, e.g. @igor-dv could probably say for sure)
I think eventually we might want to be able to customize this too but not a high priority
👍
I found the way the props/components get passed through the UI to be pretty confusing too but I can definitely say for sure that when I changed the default prop in What is confusing is that if you say yarn link The TLDR is it's easiest to do any development against the
Once it has run it shouldn't do much though? I find it takes a little while to get going but then it's OK. |
I'm able to load my preview in the iframe now but the manager has no idea what to display (which is normal I guess) https://gyazo.com/eb1810e7307ebbe74350242198f91cea Also, do you have any idea or example that you guys are already going on how to pass a CI options down to the UI / component layer? |
It looks like maybe the right messages aren't coming over the channel for the storybook. Try watching the console messages at the "debug" level and you'll see what stories are reported by your preview.
I'm not aware of it being done (although it might be) already, but I think webpack define plugin is the typical way this is done? |
PS feel free to reach out on discord |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
PR is still opened and currently in the review process... |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks! |
Huzzah!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.2.0-alpha.33 containing PR #7235 that references this issue. Upgrade today to try it out! You can find this prerelease on the Closing this issue. Please re-open if you think there's still more to do. |
Gadzooks!! I just released https://github.com/storybookjs/storybook/releases/tag/v5.2.0-alpha.34 containing PR #7245 that references this issue. Upgrade today to try it out! You can find this prerelease on the |
@shilman I'm testing the alpha release heavily and it seems like the "zoom" button are throwing an exception and make the page entirely blank. Does that ring a bell ? Should we open another issue for this ?
|
@RPDeshaies Thanks for following up on this. Yeah I think it's a new issue! |
@shilman Thanks for the awesome work, this preview-url feature is amazing! One note though: I couldn't manage to get addons to work in such setup. Not sure if I'm doing something wrong or it is not supported yet (or maybe an unrelated bug). So in my parcel entrypoint I try to add info addon: import { configure, addDecorator } from '@storybook/react';
import { withInfo } from '@storybook/addon-info';
function loadStories() {
require('../../packages/typed-form/**/*.stories.tsx');
}
addDecorator(withInfo as any);
configure(loadStories, module); And in the storybook in browser it displays loading state for eternity and in the console there is error:
Storybook version: 5.2.0-beta.4 If I remove |
@Eoksni that's possible! Mind filing a new issue so we can follow up on that? Thanks!! 🙏 |
@shilman Ok I'll try to reproduce it in a fresh setup and create new issue later today. |
@Eoksni Ideal repro is in the storybook monorepo itself, since that's where we'll be debugging and iterating. TBH your current comment is probably enough 😄 |
@shilman Unfortunately I could not set up storybook monorepo - it failed the bootstrap at the node-gyp stage with some compilation errors, so I created fresh repo here https://github.com/Eoksni/poc-storybook-preview (using @storybook/react@next) and created new issue #7514. |
Describe the solution you'd like
I would like to use my existing build process (in this case parcel-bundler) with it's own capabilities (build, serve, hmr) and omit storybook build system, just use it as library.
Describe alternatives you've considered
As my setup involves typescript I started to setup storybook as described at the official docs, but it seems to be wrong to setup a parallel build system just for storybook when I have already everything in place.
Are you able to assist bring the feature to reality?
maybe
The text was updated successfully, but these errors were encountered: