Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I specify DEV or PROD in Vite?

Tags:

vite

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

like image 582
user007 Avatar asked Nov 01 '25 05:11

user007


1 Answers

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 with NODE_ENV='production' or running an app built with NODE_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.

like image 108
user007 Avatar answered Nov 03 '25 01:11

user007



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!