Skip to content
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

Vite: Automatically use vite.config.js #19026

Merged
merged 11 commits into from
Sep 1, 2022
Merged

Vite: Automatically use vite.config.js #19026

merged 11 commits into from
Sep 1, 2022

Conversation

IanVS
Copy link
Member

@IanVS IanVS commented Aug 26, 2022

Issue:

What I did

This is an exploration into two things:

  1. Use a vite.config.js (or similar) vite config file as the basis for the storybook vite builder, while still allowing viteFinal as an override if necessary. This makes it much easier to get up-and-running with storybook in a vite project, and would also solve Babel configuration builder-vite#286, a particularly nasty issue, because we could just use the babel config that the user set in their normal vite config.
  2. Step 1 above only works if we don't need a special version of the react/svelte/vue plugins, which up to now we have. We needed to exclude .stories.x files from HMR, because it conflicted with Webpack's HMR. This approach removes those exclusions, and allows HMR to happen in stories files.

Item 2) caused a bit of problems, because vite incorrectly adds HMR boundaries to story files that it shouldn't (vitejs/vite#9869). Until/unless that issue is fixed, the approach taken here is to add one more post plugin, which looks at only .stories files, and removes import.meta.hot.accept(); if it finds it, which allows the change to bubble up and be handled correctly.

How to test

Run yarn sandbox, pick one of the vite frameworks, and answer the questions that it asks. You should then be able to go into /sandbox and start up storybook. Try configuring vite with vite.config.js, and verify that your changes appear in the vite config by logging it out in viteFinal. Verify that modifying the config in viteFinal still impacts the final build.

@IanVS
Copy link
Member Author

IanVS commented Aug 30, 2022

This is working correctly for react, and for svelte projects that do not use svelte-native stories.

I cannot yet get svelte-native stories working in 7.0, I'm not sure if it's supported yet or not. Once that's working, we may need to remove import.meta.hot.accept() from those files too, but I'm holding off on that for now.

That said, this PR is ready for review.

@IanVS
Copy link
Member Author

IanVS commented Sep 1, 2022

I see that Historie has a way to easily filter out unwanted plugins by name (https://histoire.dev/guide/config.html#ignoring-plugins), maybe that's something we could explore too. Not sure where that would go in the config file though. Maybe core.builder.options.ignoredVitePlugins?

Copy link
Member

@joshwooding joshwooding left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without deep knowledge of all the decisions here, this LGTM

@shilman shilman merged commit 3296bad into next Sep 1, 2022
@shilman shilman deleted the vite-autoconfig branch September 1, 2022 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants