-
Notifications
You must be signed in to change notification settings - Fork 106
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
feat: allow definition of stories in vue files #505
Conversation
Hey, this is awesome news! You might also want to take a look at https://github.com/storybookjs/addon-svelte-csf, which is in a similar vein of allowing stories to be written in svelte-native format. You might want to take a look at storybookjs/addon-svelte-csf#69 and the associated PR, which adds support for index file generation and compatibility with the test-runner. Have you considered creating a storybook addon which would add your vite plugin? In storybook 7.0, the vite builder will use the vite.config.js from the user, which means we won't be able to add an |
Thanks for your encouraging words and for the pointer to the svelte addon. I'm not very deep into the storybook environment, so its good to see how other projects are doing this. I learned a few good tricks while reading the code. The storybook addon is a good idea and would simplify the installation for the user. Do you have an example of an addon modifying vite-builder's vite config?
My issue was that without this exclude the transformation added by my vite plugin would have been overwritten by the vite/vue plugin. As there doesn't seem a possibility to stop a transformation chain in vite (from a plugin) and my plugin needs to be quite early in the chain, it was easiest to simple exclude the stories file from the vite/vue plugin. I guess it would also be possible (although not very nice) to instruct users to add the exclude mechanism to their vite config in v7 (or maybe do this automatically via the addon). (Thanks for the invitation to discord, but I'm not a big fan of that platform. Would prefer to continue the discussion here or in https://github.com/tobiasdiez/unplugin-storybook-vue, or via email.) |
I don't think there are any addons which do this yet, but the frameworks do. See https://github.com/storybookjs/storybook/blob/next/code/frameworks/vue3-vite/src/preset.ts#L22 for instance. Note that this will run before the user's
Could you |
Thanks, this looks simple enough. Is this a v7 specific feature or would it work with v.6.5 as well?
That's what I'm currently doing, and its working in the sense that its executed before the other plugins from builder-vite. However, I do need to exclude stories files from the vite/vue plugin, which runs later and would otherwise overwrite the changes. |
Short update from my side: The basic things are now working. In particular, I've started to add an one-to-one correspondence between the "classical" CSF format and the native vue format for the stories that are in the documentation, see https://github.com/tobiasdiez/unplugin-storybook-vue/tree/main/examples/vite/src/writing-stories. Feedback on the current state is much appreciated. Where I'm currently stuck is the handling of args in a way that feels native to vue. I've added an initial proposal that is up for discussion at tobiasdiez/storybook-vue-addon#13. What do you think? |
@Dschungelabenteuer, @shilman I wonder if maybe you have some thoughts on this exciting work to add native vue stories. See @tobiasdiez's note just above, and the links he provided. |
I've managed to find a workaround for the compatibility with the It would be nice if this PR could be merged, so that I can release an early alpha for the vue-storybook addon that people can try out and give feedback on. 🚀 |
Sorry I didn't have time to take a deep dive into the plugin itself yet! However, there are a few thoughts and questions which cross my mind while taking a quick look at @tobiasdiez's work:
Anyway, this looks cool and I'll surely give it a try soon :) |
Thanks for the feedback! Concerning your points:
|
@IanVS Can you please review this PR? Thanks! |
Hi, yes I will indeed find some time to review this, hopefully soon. |
I haven't forgotten about this, just been busy lately! Just wanted to let you know it's on my list of things to get to. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry this took me so long to get to. I think this is fine to try out. I made a small suggestion to improve the regexes, and I'm a little nervous about the source loader running on .vue files, but I'm willing to give this a shot and let you test things out further with your addon. Mind updating the regexes, and I'll get this merged and released? As long as @joshwooding doesn't have any concerns.
Co-authored-by: Ian VanSchooten <[email protected]>
Co-authored-by: Ian VanSchooten <[email protected]>
Co-authored-by: Ian VanSchooten <[email protected]>
Co-authored-by: Ian VanSchooten <[email protected]>
Co-authored-by: Ian VanSchooten <[email protected]>
Thanks for the review. I've now committed your suggested improvements to the regexes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool let's get this out there and we can iterate as needed. Thanks!
Thanks you very much! I've now released a first early-preview of the addin at https://www.npmjs.com/package/storybook-vue-addon. Please feel free to play around with it if you have the time. |
This looks quite interesting. Have you thought about using the new native format as an alternative to writing stories and documentation in mdx format, @tobiasdiez ? |
These experiments are still at a very early phase and I've not thought about the integration with mdx/documentation. How is this handled by the native svelte addon? |
I'm working on a vite plugin that transforms a vue sfc file to a standard Storybook CSF, so that one could specify stories in a format that is more convenient for vue users. This is inspired by histoire and will implement storybookjs/storybook#9768.
In this setting, stories are specified in
xyz.stories.vue
files, and then in a first step transformed to valid CSF js files. For this to work, the other vite plugins need to include or exclude these vue story files. This is done in this PR.(As a follow-up, it would probably make sense to determine the files that the vite plugins operate on by looking at the
stories
config option in.storybook/main.js
).