Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 9: file replacements doesn't work

Tags:

angular

Angular fileReplacements doesn't replace files if they occur in assets. This code doesn't work in Angular 9 but works in version 8:

"assets": [
  "src/web.config"
]
...
"fileReplacements": [
  {
    "replace": "src/web.config",
    "with": "src/configs/web.stage.config"
  }
]

How can it be fixed?

like image 364
Stas Amasev Avatar asked Feb 21 '20 12:02

Stas Amasev


1 Answers

You should copy assets using the assets property instead of file replacements.

This is a simplification of my angular.json file, showing only the relevant properties under configurations.

{  
  "projects": {
    "my-project": {      
      "architect": {
        "build": {          
          "configurations": {
            "staging": {
              "assets": [
                { "glob": "**/*", "input": "src/assets/", "output": "/assets/" },
                { "glob": "web.config", "input": "src/environments/staging/", "output": "/" }
              ],              
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.staging.ts"
                }
              ]
            },
            "production": {
              "assets": [
                { "glob": "**/*", "input": "src/assets/", "output": "/assets/" },
                { "glob": "web.config", "input": "src/environments/prod/", "output": "/" }
              ],            
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }
        }
      }
    }
  }
}

like image 189
Kurt Hamilton Avatar answered Nov 01 '22 00:11

Kurt Hamilton