Angular – Run ng build –prod with different environment settings

angularangular-clibuildpackage.jsonproduction-environment

I have different env settings for each customer with each having it's own
{{custName}}/environment.prod.ts file .
I want to use their respective prod environment files with ng build –prod command.
The problem I'm facing is even after specifiying the environment it's using the default environment.prod.ts

My package.json has script like

{.....
   customer_a : "ng build --prod --environment=custA_prod",
....}

In angular-cli.json I have mentioned the path which goes something like this

  "environments": {
        "dev": "environments/environment.ts",
        "prod": "environments/environment.prod.ts",
        "qa": "environments/environment.qa.ts",
        "custA_prod": "environments/custA/environment.prod.ts"
}

Is it possible to use all the features of prod build but with some different environment settings ?

Best Answer

After Angular 6+, angular.cli.json has been replaced by angular.json. We should use --configuration as bellow

package.json

"build_dev": "npm run && ng build --configuration=test",

angular.json

...
 "configurations": {
.....
"test": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.test.ts"
                }
              ]
            }
          }
Related Topic