How do I create an app specific configuration for Angular with NX/Nrwl?
Asked Answered
B

1

4

So I have the following project structure:

apps
├── car
└── [...]
libs
├── app-car
├── [...]
└── shared
    ├── config
    └── [...]

For every app I want to provide a different config, that can be used in the grouped libs.

export interface DefaultAppConfig {
  language: string;
}
export interface CarAppConfig extends DefaultAppConfig  {
  dealerShipName: string;
}

This is how I provide the config for every app.

But how can I typecast the config (placed in shared/config) that the CarAppConfig is used only for the group app-car and DefaultAppConfig for shared?

Brahui answered 15/11, 2021 at 10:34 Comment(2)
Could you clarify your question a little more? I think you're asking how to have strongly-typed configuration per app, but using a config service (to load configuration) which is in shared. Is that right?Sf
@MattTester I haven't thought of the placement yet, but placing it in shared/config would be a good option. I also edited the question and added the placement of the service. libs/shared is a group of libs. Libs that are used across all apps are placed here. Yes I want a strongly-typed configuration per appBrahui
L
3

From what I can understand, IMHO, you should keep DefaultAppConfig in shared/config and CarAppConfig in app-car.

Reason: As the name suggest, shared is shared by all libs. So, why should other app have access to an object which is out of its scope.

You can extend DefaultAppConfig in all apps and use it in its app-car.module or something.

Side note: You can also explore the concept of Tags to have more control over what can be imported into a lib and what should not.

Please let me know if I get it correctly.

Labarbera answered 22/11, 2021 at 14:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.