I am developing an angular application which is a product and deployed to multiple clients. Clients will take this angular application and host it in their servers. So the S
For the config to be loaded initially and use it even when bootstrapping the AppModule, we used this simple solution in main.ts.
notice we queued the
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
inside an async function that waits for the fetching of a config file.
(async () => {
// console.time()
const response = await fetch('./assets/config/conf.json');
const json = await response.json();
Object.entries(json).forEach(([key, value]) => {
environment[key] = value;
});
// console.timeEnd()
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.error(err));
})();
the config file is located in the assets and is replaced accordingly by the deployment job.
meaning we have environment based config:
time of fetching on for us takes about 40 milliseconds (practically nothing. uncomment the console.time to check estimations in your own projects). I doubt it will consume too much time on any project as it is fetched from a local file. good luck!