Search code examples
angulardockerdockerfile

Angular environments local no file replacement


I have configurations in angular.json for both development and production. What I want is for locally (ng serve) the file replacement doesn't happen. But when I docker build etc it does happen. Now I can make another environment but can't I just use environment.ts by default during ng serve?

configurations

            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
            "development": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.dev.ts"
                }
              ],

So with development if I remove the file replacement it will use of course the environment.ts.

serve:

            "production": {
              "browserTarget": "my-app:build:production"
            },
            "development": {
              "browserTarget": "my-app:build:development"
            }
          },
          "defaultConfiguration": "development"
        },

Now I could create another environment but doesn't make much sense (I know it is probably weird trying to avoid doing so) - would I just make one called local and make that the default configuration or what does everyone else do?

Summary:

  • Two environments
  • I want file replacement for my docker builds but not locally (so using environment.ts locally and development during builds)
  • Avoiding creating another configuration

Solution

  • I think that you need another configuration called local.

    Build:

                "local": {
                  "fileReplacements": [
                  ],
                }
    

    Serve:

                "local": {
                  "browserTarget": "my-app:build:local"
                },
    

    and then

    ng serve --configuration=local or change "defaultConfiguration": "development" to "defaultConfiguration": "local" if it makes it easier for you