[Vuejs]-Unable to read the environmental variable in the contect of VueJS

1👍

Create in the same level of src folder a file

.env.development.local is used for working locally

.env.production.local is used for production

Add in the file your env variable

VUE_APP_MY_VARIABLE_NAME = my-value-here

VUE_APP_* part is important because all env variables in vue project needs to start with this prefix.

Now to get access on this value do:

process.env.VUE_APP_MY_VARIABLE_NAME

IMPORTANT STEP

Whenever you modify the .env files you have to stop your server and start it again in order to get the env changes.

1👍

I guess you are using vue-cli to build your vue project. In the vue-cli docs, I found the grammar of env.local would be

VUE_APP_WEB_SITE=testing-hard-reality

not your demo: VUE_APP_WEB_SITE: 'testing-hard-reality'

ref: https://cli.vuejs.org/guide/mode-and-env.html#environment-variables

Leave a comment