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

Built-in .env support #989

Closed
brillout opened this issue Jul 1, 2023 · 8 comments
Closed

Built-in .env support #989

brillout opened this issue Jul 1, 2023 · 8 comments
Labels
enhancement ✨ New feature or request

Comments

@brillout
Copy link
Member

brillout commented Jul 1, 2023

Description

While Vite has built-in support for .env files, it only includes environment variables prefixed with VITE_.

The official recommendation is to install dotenv. But better yet, vite-plugin-ssr should have built-in support including niceties such as HMR and accessing all environment variable over import.meta.env (only on the server-side of course). Maybe also changing the prefix from VITE_ to PUBLIC_.

@brillout brillout added the enhancement ✨ New feature or request label Jul 1, 2023
@carlreid
Copy link

carlreid commented Jul 1, 2023

This would be great! Was just trying to find why the .env.local values weren't being loaded via /server/index.ts, which I assume related to this.

@brillout
Copy link
Member Author

brillout commented Jul 1, 2023

You're right and I'm realizing that the new docs actually don't work for the server-side. I'll implement it tentatively this weekend.

@brillout
Copy link
Member Author

brillout commented Jul 3, 2023

Almost done, I'll finish tomorrow.

@brillout
Copy link
Member Author

brillout commented Jul 4, 2023

Done: use 0.4.133 and see udpated docs https://vite-plugin-ssr.com/env.

Was just trying to find why the .env.local values weren't being loaded via /server/index.ts, which I assume related to this.

As descried in the docs, you'll still need to manutally install dotenv until #562 is implemented.

Closing: once #562 is implemented I'll consider environement variables to have well polished DX.

@brillout brillout closed this as completed Jul 4, 2023
@carlreid
Copy link

carlreid commented Jul 5, 2023

Wonderful. Thanks for the quick turnaround !

@brillout
Copy link
Member Author

brillout commented Jul 5, 2023

Sure 👍 Btw. in case you're able to convince your employer: https://github.com/sponsors/brillout — it has a substantial impact.

@carlreid
Copy link

carlreid commented Jul 5, 2023

In this case, it's just for a personal project. Though if I do use it for my employer then I will for sure 😊

@brillout
Copy link
Member Author

brillout commented Jul 5, 2023

Thanks & have fun with your personal project (can't wait to fix all paper cuts and release the v1 👀).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants