window.ENV vs process.env vs window._env what is difference while using in vuejs apps?

Viewed 3811

I recently started working in vue js and while trying to make run time url injection in vuejs app deployed using docker container in docker ucp, I came across window.ENV and window._env. I read about process.env to be used in order to use environment variables into application. But not sure how window.ENV or window._env or process.env are different? Thanks in advance for your help!!

2 Answers

If you are using vue-cli with VueJS process.env is used by webpack in the build process to set the environment variables into your script when building for production. It will replace the process.env.VARNAME with the VARNAME value you specify on the .env and .env. files...

It is also processed and replaced in the development webpack development server.


process and process.env is not understood by the browser. (test out by running console.log(process) in the browser dev console).


window on the other hand is an object available in the browser on your site...

you can add your own objects to it such as

window.CONFIG= {}
window.ENV = {}

console.log(window) before and after you create the objects to see the effects.

There is a typo in your example: The right access to the Window object is without the final 's'

window.ENV = {}
Related