I'm working on Angular 2/4/5 application for a while now (that's why 2/4/5), using webpack
to bundle everything, etc. The application itself communicates with a backend API written in C#. We're at a stage right now that we need to support 4 different environments which results in 4 different endpoints for the mentioned backend API, so I started exploring options how I can replace the values for the endpoints during npm run build:environment
in combination with VSTS build definition that should also do the transformation when running a specific script.
This is how the config file looks like:
const AppConfig = {
hubName: "eventhub",
baseApiUrl: "https://endpoint.com/api/",
baseUrl: "https://endpoint.com/"
};
I started with webpack.prod.js
and webpack.dev.js
and I have two scripts configured: build:prod
and build:dev
. Both of those webpack
files are setting the value for process.env.ENV
to production
and development
respectively. Using that info, I tried reading the value for process.env.ENV
in config.ts
file and just doing switch/case
and setting the value for baseApiUrl
and baseUrl
based on the value, however that didn't work, it kept defaulting back to development
all the time, so I abandoned that approach and started exploring other options, like using normalModuleReplacementPlugin
for webpack
, but with little success.
Are there any better ways of replacing specific properties of a config file during execution of the build task?