I use a build server to build my Vue projects, using the npm run build
command nicely supplied by the Vue 2 template. The Vue template also provides the ability to access environment-specific data that can be configured in files underneath the config
directory. Things like prod.env.js
, etc. You then access this data through process.env.API_PREFIX
as seen in the template manual.
I want to be able to build the code once, then deploy the same build (as defined by the output in Dist
) to multiple servers, but have the different servers use different configuration (different API_PREFIX
etc). Currently, the process.env
references are expanded at build time by the Webpack compiler. Therefore I have to rebuild for every environment.
I can think of a few ways to do this -- obviously the loading of the config has to happen at runtime, and given that it runs in the browser and has to refer to some file, it would have to be through an AJAX request for some static JSON configuration served by the web server separately, or similar. But I'd be interested to know how anyone here would handle this requirement.
staging
deployment environment, the API prefix might behttps://staging-api.mycompany.com
. [it's not derivable in principle from the name of the environment, though.]