Replies: 1 comment
-
Great question! And it still hasn't been answered after two years? Fascinating (in the Spock way). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi!
First, thank you for maintaining such a fancy tool. I'm happy using vite and my developing experience got much better with vite.
This discussion is not about troubleshooting or feature request. I am just curious about:
Why did vite select import.meta.env for providing environment variables?
After some researches, I thought these could be the reason:
import.meta
is included in ECMA2021 spec, whileprocess.env
is not.import.meta
is more "official" one.import.meta
can be used in browser-side whileprocess
object cannot. So there are some technical issues, because vite uses browser-supported native ESModule.However, there are some downsides also:
process.env
is heavily used in frontend ecosystem. Many third-party libraries & existing projects would be break if vite does not supportprocess.env
. Of course, we can useprocess.env
in vite using plugins like vite-plugin-environment. Anyway there is a big difference between "supported officially" and "supported by third-party plugin".import.meta
is an official one, butimport.meta.env
is not an official one. As I know, vite is the only one that usesimport.meta
for providing env variables. So it didn't have to beimport.meta
, many other solutions would have existed. (ex.globalThis
?) If some other thing becomes an "official & trending" thing for env in future, vite ecosystem developers will have to migrate their codebase.process.env.NODE_ENV
(source code here). So with similar thing, it would not be technically hard to support bothprocess.env
andimport.meta.env
, or onlyprocess.env
.So returning to my first question: why did vite select import.meta.env for environment over process.env? What was your basis of judgement? Why it had to be
import.meta.env
over other existing solutions?Thank you for reading my long question! 😄
Beta Was this translation helpful? Give feedback.
All reactions