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

Inject storybook environment variables #105

Merged
merged 3 commits into from Sep 29, 2021
Merged

Inject storybook environment variables #105

merged 3 commits into from Sep 29, 2021

Conversation

IanVS
Copy link
Member

@IanVS IanVS commented Sep 29, 2021

Fixes #104.

This injects storybook environment variables through the define config of vite, similar to what the webpack builder does using the DefinePlugin. I needed to create a customized version of one of the core storybook functions, since it assumes that process.env is going to be used, whereas with vite we use import.meta.env.

I also added example stories in react, vue, and svelte (my first time writing vue and svelte!). They're ugly, but they show that the STORYBOOK environment variable is being provided correctly (it wasn't previously).

Before:
image

After:
image

@IanVS IanVS requested a review from eirslett September 29, 2021 01:59
@eirslett
Copy link
Collaborator

Do we risk exposing process.env.SUPER_SECRET_PASSWORD if that is somehow set up as an environment variable on the server?

@IanVS
Copy link
Member Author

IanVS commented Sep 29, 2021

No, because storybook only finds variables starting with STORYBOOK_. That's why I'm using preset.apply("env").

@IanVS IanVS merged commit 4ab1512 into main Sep 29, 2021
@IanVS IanVS deleted the 104-env-vars branch September 29, 2021 12:28
@FezVrasta
Copy link

FezVrasta commented Aug 26, 2022

environment variables starting with VITE_ are not being injected into the production builds, only ones starting with STORYBOOK_ are. Also STORYBOOK is missing too. Is this expected?

@IanVS
Copy link
Member Author

IanVS commented Aug 30, 2022

@FezVrasta I responded to your issue: #489

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

Successfully merging this pull request may close these issues.

Environment variables are not injected
3 participants