0π
β
It should be possible to conditionally evaluate Javascript according to the execution mode (production or development) by using the import.meta.env
variable.
vite dev
will run in development mode by default and vite build
will use production mode (you can override though through --mode
)
See https://vitejs.dev/guide/env-and-mode.html#modes
In your case you can use import.meta.env.DEV
to see if you are in development mode and run conditionally some code, e.g.:
if (import.meta.env.DEV) {
// code runs in vite dev
}
Source:stackexchange.com