vikejs / vike

🔨 Flexible, lean, community-driven, dependable, fast Vite-based frontend framework.
https://vike.dev
MIT License
3.88k stars 334 forks source link

Improve environment variables support #1726

Open brillout opened 6 days ago

brillout commented 6 days ago

Description

7iomka commented 4 days ago
image

Why my import.meta.env is undefined?

brillout commented 4 days ago

@7iomka It's a Vite design limitation: import.meta.env isn't defined in any config file, neither inside Vite's vite.config.js file nor inside Vike's +config.js files.

Because, in order to determine whether the production or development environment variables should be applied, the value of Vite's mode setting needs to be known. And note that mode can be defined inside vite.config.js.

A possibility would be to stop using Vite's mode implemention and have Vike implement its own mode feature. (While we could make import.meta.env work inside +config.js and vike.config.js files, I ain't sure we could make it work inside vite.config.js files: to be researched.)