Replies: 3 comments 12 replies
-
If introducing |
Beta Was this translation helpful? Give feedback.
-
I agree with all three of your Problem ideas and your two Others ideas (assuming Rich's clarification) with the one caveat: In Problems
|
Beta Was this translation helpful? Give feedback.
-
Just got hit by this problem, took quite a while to find this discussion. Running
This behavior change from Are there any options to do a build with |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Partially implemented in #10996
There are a few complications with how these vars interact with each other:
import.meta.env.DEV
import.meta.env.PROD
mode
process.env.NODE_ENV
Problem
resolveConfig
it setsprocess.env.NODE_ENV
ifmode
isproduction
, this could be unexpected when running the dev server, build, or both, in parallel or sequentially.Idea: Avoid setting
process.env.NODE_ENV
inresolveConfig
. Set it elsewhere (continued below).development
orproduction
until.env
is loaded, because plugins can changeenvDir
&mode
in theconfig
hook. However this cause a second issue since some plugins need to know eitherdevelopment
orproduction
before theconfig
hook. (e.g.@vue/compiler-*
)Idea: Let the user set
process.env.NODE_ENV
themselves. Ifundefined
, auto-setdevelopment
invite dev
,production
invite build
(regardless ofmode
) in the CLI (orcreateServer
/build
?)Also remove the
NODE_ENV
configuration in.env
files as it's unused.mode
other thanproduction
, Vite builds for development, which may not be a good fallback. (Though this is documented)Idea: Relying on idea no2 which should solve this, also set
import.meta.env.DEV = process.env.NODE_ENV !== 'production'
andimport.meta.env.PROD = process.env.NODE_ENV == 'production'
instead.Others
import.meta.env.COMMAND
if users want to differentiate between that specifically.command === 'preview'
when callingvite preview
Related issues
import.meta.env.DEV
andPROD
are incorrect if a custommode
is provided programmatically #9203 (comment)Beta Was this translation helpful? Give feedback.
All reactions