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

Ensure no duplicate code in preview when using vite #20594

Merged
merged 2 commits into from
Jan 13, 2023

Conversation

ndelangen
Copy link
Member

Issue: #20514

What I did

I switched out one rollup plugin for a vite plugin, and after a bit of experimentation I found the setting that would cause no duplicate code, and make vite 100% use the prebundled code, and never include prebundled code

@ndelangen
Copy link
Member Author

@ndelangen ndelangen requested a review from IanVS January 12, 2023 16:50
@ndelangen ndelangen self-assigned this Jan 12, 2023
@ndelangen ndelangen added the bug label Jan 12, 2023
@ndelangen
Copy link
Member Author

I verified that getSelectionSpecifierFromPath is only defined once in the preview in these 4 situations:

  • webpack dev
  • webpack build
  • vite dev
  • vite build

Copy link
Member

@IanVS IanVS left a comment

Choose a reason for hiding this comment

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

Oh wow, nice win! Thanks for figuring this one out.

@thebuilder
Copy link
Contributor

@ndelangen see #20643 - It appears the vite-plugin-externals plugin breaks HMR. Might work with the disableInServe: true option? Can it be set true in dev in dev mode?

@IanVS
Copy link
Member

IanVS commented Jan 17, 2023

@thebuilder Thanks, but unfortunately we need to replace the externals in dev as well. You can watch #20655 for any progress.

@IanVS
Copy link
Member

IanVS commented Jan 23, 2023

@ndelangen I'm testing out a different approach, but not sure it's doing what we want. Could you explain the method you used to verify that getSelectionSpecifierFromPath is only included once in the preview?

I found that searching in node_modules/.cache/storybook-vite is a good way in dev, and in storybook-static for builds.

@ndelangen
Copy link
Member Author

@IanVS the way I used was this:

  • I start storybook in dev-mode (using vite). any sandbox with vite will do.
  • I open the browser and open dev-tools
  • I open the global search tool ,and search for the string I know will appear in the prebundle, and should NOT be in the vite-bundle.
  • If it finds it twice, I know things are wrong.

Screenshot 2023-01-23 at 11 51 18

I then do the same for build-mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants