If your project was create by using Vue CLI 3, no need to use dotenv to get environment variables.
To get environment variables within .env file in your project:
- Placing the
.envfile in your project root. -
In the
.envfile, specifying environment variables with “VUE_APP_” prefix.VUE_APP_SOMEKEY=SOME_KEY_VALUE. -
Finally, you can access them with
process.env.*in your application code.console.log(process.env.VUE_APP_SOMEKEY) // SOME_KEY_VALUE
Referance: Vue CLI 3 – Environment Variables and Modes