Configuration library for Angular handling environments in continuous delivery systems.
Why using ng-config?
Angular comes with built-in mechanism of environment files but this mechanism requires you to build for each environment. This approach doesn't fit to modern development paradigm which advocate for
build once - deploy anywhere.
npm install @golavr/ng-config --save
- Add more
assets/configs/config.$$$.jsonfiles to support all environments.
You should have this folder structure:
- assets - configs - config.json - config.prod.json - env.json
Note: Library depends on the above folder and file names.
assets/configs/env.json and add this content:
In continues delivery system you should edit the
env value to target the selected environment.
Note: you can replace
prodwith other environment
$$$as long as you have
assets/configs/config.$$$.jsonfile for it.
How to use?
Lets set two configuration values for demonstration purpose.
assets/configs/config.json file and add:
assets/configs/config.prod.json file and add:
Create interface reflecting the configuration:
Inject it and use it:
How does it work?
Each request will read config values during the call, so changes can be made to config files while the app is running.
The returned config object will be composed from
config.json and will be overridden with env config.
In continues delivery system you need to edit
env.json and set which env config (
config.prod.json) will be selected at runtime.
You can have multiple env config files like