DEV Community

Discussion on: How to use dynamic environment variables in VueJS

Collapse
 
entioentio profile image
entio

Thanks for the article, I was struggling with this issue not too long ago. Interesting approach. Personally I used DotEnv plugin for webpack and I saved configuration per environment in .env file. But then it requires different builds (or building on the server and picking right .env file).

What you present here solves the problem, but adds one call before the app can launch.

Since you have to manually (or using some pipeline) replace the file - wouldn't it be easier to build app with parameter? Let's say npm run build --test or npm run build --dev and pass the arguments?

Collapse
 
djdany01 profile image
Dani J. Pérez

I'm glad it helped you!

And yes, i think you can develop a npm script to build with the file you want automatically, but i want to just build one time and then, with Jenkins, deploy the right file.
But yes, this can be done in a very different ways.