Rohith Murali
Rohith Murali

Reputation: 5669

In Angular 9, how can I replace the configuration file in assets folder during an ng build?

I have an Angular 6 project which I now upgraded to Angular 9. After upgrading I am not able to replace the .json configuration file in assets folder with a configuration file in environments folder. I have several configuration files in the environments folder corresponding to different staging environments. While the application is build using the below command,

ng build --prod --base-href=/ --configuration=staging_<number>

All the replacement list is mentioned in angular.json like,

{
  ...
  "projects":{
  ...
    "architect":{
    ...
      "build":{
      ...
      "configurations"{
        "staging_<number>": {
              "budgets": [
                {
                  "type": "anyComponentStyle",
                  "maximumWarning": "6kb"
                }
              ],
              "fileReplacements": [
                {
                  "replace": "src/assets/appsettings_config.json",
                  "with": "src/environments/appsettings_config_stg_<number>.json"
                }
              ],
              "sourceMap": true
             ..

Before upgrading the replacements were working fine. Now when I run the above command the application is build with the same configuration file which is already in the assets folder. ie, appsettings_config.json and not appsettings_config_stg_<number>.json. What could have been the difference between Angular version 6 and 9 in the file replacement functionality?

Upvotes: 2

Views: 7799

Answers (1)

Miq
Miq

Reputation: 4289

File replacements are meant to be used with bundles, not assets. It was a glitch that it was working before.

Angular team is trying to work on this but seems, like they have more important things (https://github.com/angular/angular-cli/issues/8808).

However for a workaround see https://github.com/angular/angular-cli/issues/16779

Upvotes: 2

Related Questions