Skip to content

Concatenate fileReplacements in the configs so that we can easily have whitelabel and environment configurations #28831

@CHAZTATS

Description

@CHAZTATS

Command

build, serve, test

Description

My current project requires the following.
I have brands A, B and C.
I have environments, dev, test and prod.

I want to be able to run ng build -c=BRANDNAME, ENVIRONMENTNAME and have the brand config file replaced along with the environment file being replaced.
HOWEVER it only takes into the account the last configs file replacement array.

Thank you all :)

I have set up the following configurations and files in my angular.json and project.

"configurations": {
            "production": {
              
              "budgets": [
                {
                  "type": "initial",
                  "maximumWarning": "500kB",
                  "maximumError": "1MB"
                },
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "2kB",
                  "maximumError": "4kB"
                }
              ],
              "outputHashing": "all",
              "fileReplacements": [
                {
                  "replace": "config/environment/environment.ts",
                  "with": "config/environment/environment.prod.ts"
                }
              ]
            },
            "development": {
              "optimization": false,
              "extractLicenses": false,
              "sourceMap": true
            },
            "test": {
              "optimization": false,
              "extractLicenses": false,
              "sourceMap": true,
              "fileReplacements": [
                {
                  "replace": "config/environment/environment.ts",
                  "with": "config/environment/environment.test.ts"
                }
              ]
            },
            "staging": {
              "optimization": false,
              "extractLicenses": false,
              "sourceMap": true,
              "fileReplacements": [
                {
                  "replace": "config/environment/environment.ts",
                  "with": "config/environment/environment.stag.ts"
                }
              ]
            },
            "BRANDA": {
              "assets": [
                {
                  "glob": "*",
                  "input": "public/assets"
                },
                {
                  "glob": "**/*",
                  "input": "public/assets/BRANDA"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "config/brand/brand.ts",
                  "with": "config/brand/BRANDA.ts"
                }
              ],
              "styles": [
                "src/styles.scss",
                "src/themes/BRANDA.scss"
              ]
            },
            "BRANDB": {
              "assets": [
                {
                  "glob": "*",
                  "input": "public/assets"
                },
                {
                  "glob": "**/*",
                  "input": "public/assets/BRANDB"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "config/brand/brand.ts",
                  "with": "config/brand/BRANDB.ts"
                }
              ],
              "styles": [
                "src/styles.scss",
                "src/themes/BRANDB.scss"
              ]
            }
          }

Describe the solution you'd like

I want to be able to run ng build -c=BRANDNAME, ENVIRONMENTNAME and have the brand config file replaced along with the environment file being replaced.
HOWEVER it only takes into the account the last configs file replacement array.
Essentially the lists of file replacements should concatenated in order to allow a really clean solution for multiple configs and whitelabels.

Describe alternatives you've considered

I've considered copy pasting over and over again and making configs such as BRANDA-DEV, BRANDB-DEV, BRANDA-STAGING etc.
But I feel that this is incorrect and incredibly time consuming if we have to add more brands regularly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions