When building my Vue projects using a build server, I rely on the npm run build
command provided by the Vue 2 template. This template allows me to access environment-specific data configured in files within the config
directory, such as prod.env.js
. The accessed data is available through process.env.API_PREFIX
, according to the template manual.
I am looking for a solution that would enable me to build the code once and deploy the same build (defined by the output in Dist
) to multiple servers with different configurations (various API_PREFIX
values). Currently, the references to process.env
are resolved at build time by the Webpack compiler, necessitating a separate rebuild for each environment.
I have considered various approaches to address this issue. It seems apparent that config loading must occur at runtime, likely involving an AJAX request for static JSON configuration served separately by the web server. I am curious to hear how others would approach this requirement.