I have an Angular project where I can build the project for a given environment and run it. I've realized this bakes the environment settings into the built project. Now I want to load the environment-specific settings at run time.
So, I've currently got this:
import { EnvConfig } from '../../../../../tools/env/env-config.interface';
export const Config: EnvConfig = JSON.parse('<%= ENV_CONFIG %>');
Where <%= ENV_CONFIG %>
gets replaced with the baked environment settings. Other files import Config
and then use it directly like:
import { Config } from '../shared/config/env.config';
export function main() {
console.log(`Environment: ${Config.ENV}`);
}
I've been looking at something like this solution, but it seems I'd have to switch everything from using Config
directly to using an injected ConfigService
.
Do I need to switch from a constant to a service in order to support the run-time load? If not, how do I create the constant on the fly?