Reputation: 85
Vue states that environment variables will be
statically embedded into the client bundle
However given this behaviour it appears impossible to store environment variables on the server. For example if there are multiple servers each with different backend URLs(which is stored as a environmental variable) one would have to build the frontend for each server individually instead of just putting the build client bundle on the server. The same Problem also occurs if the IP of the backend changes.
Is there any way to put something similiar to an .env file next to the build .js files and use it?
Upvotes: 3
Views: 284
Reputation: 8746
The goal of bundling your code is to reduce network round trips caused by nested imports. So if you want to separate your .env
file you need an additional request to fetch that file. Think of that, it is the same as calling an API request. So wrapping your .env
variables on an API is an easier option.
In case you still want to place a separate .env
file on your server, it is not related to Vue actually. You can just manually or automatically (depending on what server you are using) put your file on your server and fetch it from Vue code via relative/absolute path.
Upvotes: 2