runtime-config-loader 6.0.0 → 6.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,51 +8,50 @@ This library provides an easy way to load one or more JSON files with configurat
8
8
 
9
9
  ## How to Implement
10
10
 
11
- In your `app.module.ts` file, add the following to the `@NgModule` decorator:
11
+ In your `app.config.ts` file, add the following to the `providers` array:
12
12
 
13
13
  ```ts
14
- imports: [..., RuntimeConfigLoaderModule, ...],
14
+ import { provideRuntimeConfig } from 'runtime-config-loader';
15
+
16
+ export const appConfig: ApplicationConfig = {
17
+ providers: [
18
+ ...,
19
+ provideRuntimeConfig({ configUrl: './assets/config.json' }),
20
+ ...
21
+ ]
22
+ };
15
23
  ```
16
24
 
17
- That's it; it's that simple. In the `RuntimeConfigLoaderModule`, the `APP_INITIALIZER` token is used to run a function which loads the configuration from a file or an API endpoint that can be used throughout the application.
25
+ That's it; it's that simple. The `provideRuntimeConfig` function sets up the `APP_INITIALIZER` token to load the configuration from a file or an API endpoint before the application starts.
18
26
 
19
- If you implement the library exactly as it is above, the configuration file needs to be in the `./assets/config.json` location as mentioned above. If you'd like to load the file from a different location, provide that location in the `.forRoot()` method when importing the `RuntimeConfigLoaderModule`:
27
+ ### Configuration
20
28
 
21
- ```ts
22
- imports: [
23
- ...,
24
- RuntimeConfigLoaderModule.forRoot(
25
- { configUrl: './path/to/config/config.json' }
26
- ),
27
- ...]
28
- ```
29
+ The `provideRuntimeConfig` function accepts a configuration object with a `configUrl` property. This can be a single string or an array of strings.
29
30
 
30
- If you want to load multiple files, the value of `configUrl` should be an array of strings:
31
+ #### Single Config File
32
+
33
+ The default location is `./assets/config.json`. If you'd like to load the file from a different location:
31
34
 
32
35
  ```ts
33
- imports: [
34
- ...,
35
- RuntimeConfigLoaderModule.forRoot(
36
- { configUrl: ['./path/to/config/config-1.json', './path/to/config/config-2.json'] }
37
- ),
38
- ...]
36
+ provideRuntimeConfig({ configUrl: './path/to/config/config.json' });
39
37
  ```
40
38
 
41
- > Make sure that the path(s) you provide here is accessible by the Angular application, meaning that the file is somewhere the app can load it. In my opinion, the `assets` folder is the easiest place to work from.
42
-
43
- ## Multiple Config Paths
39
+ #### Multiple Config Files
44
40
 
45
- One reason you may want to load multiple configuration objects is so that you can set the configuration on your machine without affecting anyone else. For example, you could have a `local.config.json` file that is not included in source control. Some of the values in that file would overwrite the values in a config file that everyone can use. Another use case is that some config values don't change between environments, and some do. The ones that don't change could go in one file, the ones that do change could go in a second file. Each developer/environment can provide the second file with values they want or need.
46
-
47
- It's important to know that if an attribute is repeated in two configuration files, the latest value is kept. So, let's say you have `apiUrl` in both files, `config-1.json` and `config-2.json`. Let's assume the files are passed in to the `forRoot` method like this:
41
+ You can load multiple files (or API endpoints) and they will be merged into a single configuration object.
48
42
 
49
43
  ```ts
50
- imports: [
51
- ...,
52
- RuntimeConfigLoaderModule.forRoot(
53
- { configUrl: ['./path/to/config/config-1.json', './path/to/config/config-2.json'] }
54
- ),
55
- ...]
44
+ provideRuntimeConfig({
45
+ configUrl: [
46
+ './path/to/config/config-1.json',
47
+ './path/to/config/config-2.json',
48
+ ],
49
+ });
56
50
  ```
57
51
 
58
- In this case, the `apiUrl` value from `config-2.json` will override the value from `config-1.json`.
52
+ If an attribute is repeated in multiple configuration files, the latest value is kept. For example, if `apiUrl` exists in both files above, the value from `config-2.json` will override the value from `config-1.json`.
53
+
54
+ > [!TIP]
55
+ > This is useful for maintaining local overrides (e.g., `local.config.json` ignored by git) or separating environment-specific values from global ones.
56
+
57
+ Make sure that the path(s) you provide are accessible by the Angular application. The `assets` folder is generally the easiest place to serve these files.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "runtime-config-loader",
3
- "version": "6.0.0",
3
+ "version": "6.0.1",
4
4
  "author": {
5
5
  "email": "preston.j.lamb@gmail.com",
6
6
  "name": "Preston Lamb",
Binary file
Binary file