[Vuejs]-Vite: Is there a possibility to exclude code elements from being built?

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
}

Leave a comment