In the Vite documentation I read the following:
import.meta.env.PROD: {boolean} whether the app is running in production.
import.meta.env.DEV: {boolean} whether the app is running in development (always the opposite of import.meta.env.PROD)
However, I can't find how these variables are defined or configured.
When I build the application [npm run build or npm run build --mode production] this is what the value of import.meta.env is when I log it:
{
BASE_URL: "/",
MODE: "production",
DEV: true,
PROD: false
}
Which is also rather confusing since the mode is set to production, but the PROD value is not.
How can I specify the PROD or DEV value? Setting PROD=true in my .env file is not resolving the problem (as expected).
In case it helps, I am running Vite version 4.4.4
I found this commit with a request to update the documentation:
import.meta.env.PROD: {boolean} whether the app is running in production (running the dev server withNODE_ENV='production'or running an app built withNODE_ENV='production').
This clarifies how the PROD value can be set, by setting NODE_ENV to production. Since DEV is the opposite of PROD, setting NODE_ENV to production will set DEV to false.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With