简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM