What is the right way to add an environment configuration to angular.json? What is the right way to add an environment configuration to angular.json? angular angular

What is the right way to add an environment configuration to angular.json?


AFAIK This is not really documented anywhere yet. However you should be able to override the build options you specify with browserTarget. Alternatively, specify another build config in the build command section.

Best "docs" I've found so far are here https://blog.ninja-squad.com/2018/05/04/angular-cli-6.0/

UPDATE: There's an issue for this issue, https://github.com/angular/angular-cli/issues/10612

Also some not-especially-amazing docs https://github.com/angular/angular-cli/wiki/angular-workspace. For now you must specify each config individually, regardless of overlapping options. The only "workaround" I can think of for this is to use some other utility to merge json files pre serve/build

    "serve": {      "builder": "@angular-devkit/build-angular:dev-server",      "options": {        "browserTarget": "bb-admin:build"      },      "configurations": {        "local": {          "browserTarget": "bb-admin:build:local"        }      }    },


I add in package.json under "scripts" something like

"myscript": "ng serve -c local-version"

Than I add to angular.json under "configurations"

"local-version": {            "fileReplacements": [                {                    "replace": "src/environments/environment.ts",                    "with": "src/environments/environment.local.ts"                }            ]        }

and under "serve"

"configurations": {        "local-version": {          "browserTarget": "your-app:build:local-version"        }

I start the app with:

npm run myscript

Of course you have to create a file called environment.local.ts