How to manage .env files in Nuxt 3 when transitioning from Vue 3 to a Nuxt 3 project?

130 views Asked by At

In a Vue project, my colleage typically set up four files in the root directory: .env, .env.dev, .env.prod, and .env.stage. Each of these files contains two variables: VUE_APP_BASE_URL and VUE_APP_API with different values.

To my understanding, in Vue projects, when you run 'npm run dev,' it automatically selects variables from .env.dev. When you run 'npm run production,' it uses the variables from .env.prod.

However, in Nuxt 3, it seems that we need to set the runtimeConfig in nuxt.config.ts and define the variables in .env. My question is, how can we distinguish which environment variables 'npm run dev' and 'npm run production' will use in Nuxt3?

Nuxt3 instructions are not clear for me : https://nuxt.com/docs/guide/directory-structure/env

0

There are 0 answers