Search code examples
angularnrwl-nxnrwl

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


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?


Solution

  • 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.