Skip to content

Vite: Fix static source handling for addon-docs#20147

Merged
shilman merged 1 commit into
nextfrom
add-csf-plugin-to-vite
Dec 8, 2022
Merged

Vite: Fix static source handling for addon-docs#20147
shilman merged 1 commit into
nextfrom
add-csf-plugin-to-vite

Conversation

@joshwooding

@joshwooding joshwooding commented Dec 8, 2022

Copy link
Copy Markdown
Contributor

Issue: #19882 #19554

What I did

  • Add csf-plugin

How to test

  • Is this testable with Jest or Chromatic screenshots?
  • Does this need a new example in the kitchen sink apps?
  • Does this need an update to the documentation?

If your answer is yes to any of these, please make sure to include it in your PR.

@joshwooding joshwooding force-pushed the add-csf-plugin-to-vite branch from 02d988c to 9d074e6 Compare December 8, 2022 01:55
@@ -0,0 +1,15 @@
import type { Plugin } from 'vite';

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Kept a plugin so vite-config stayed clean

@IanVS IanVS left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This really simplifies things nicely! The only part I'm not sure about is getting the settings from addon-docs. @shilman is this something that @storybook/csf-plugin itself should be doing, maybe?

// @ts-expect-error - not sure what type to use here
addons.find((a) => [a, a.name].includes('@storybook/addon-docs'))?.options ?? {};

return vite(docsOptions?.csfPluginOptions);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It feels to me like @storybook/csf-plugin itself should take care of this...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think csf-plugin should know about the user's main.js and it makes sense for addon-docs to glue things together like this. Hopefully this all goes away in 7.x with the annotations server & simplifies things even further.

@shilman shilman changed the title Add csf-plugin to vite Vite: Add csf-plugin handling for addon-docs Dec 8, 2022
@shilman shilman changed the title Vite: Add csf-plugin handling for addon-docs Vite: Fix static source handling for addon-docs Dec 8, 2022

@shilman shilman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks great! 💯

// @ts-expect-error - not sure what type to use here
addons.find((a) => [a, a.name].includes('@storybook/addon-docs'))?.options ?? {};

return vite(docsOptions?.csfPluginOptions);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think csf-plugin should know about the user's main.js and it makes sense for addon-docs to glue things together like this. Hopefully this all goes away in 7.x with the annotations server & simplifies things even further.

@shilman shilman merged commit 903c037 into next Dec 8, 2022
@shilman shilman deleted the add-csf-plugin-to-vite branch December 8, 2022 06:20
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.

3 participants