Angular 7: How to use fileReplacement globaly

462 views Asked by At

I`m using Angular 7 and i would like to know if exist any way to replace files no matter the enviroment using fileReplacement. Something like this: The problem tight now is that we are using the standard approach and we are forcing to replicate the replaced files in every environments.

    "configurations": {
      "production": {
        "fileReplacements": [
          {
             "replace": "src/app/modules/corporate/MainFooter/main-footer-container/socialmedia/styles/socialmedia.style.scss",
                  "with": "src/app/modules/corporate/MainFooter/main-footer-container/socialmedia/styles/socialmedia.inline.style.scss"
          }
        ],
      },
"stage": {
        "fileReplacements": [
          {
             "replace": "src/app/modules/corporate/MainFooter/main-footer-container/socialmedia/styles/socialmedia.style.scss",
                  "with": "src/app/modules/corporate/MainFooter/main-footer-container/socialmedia/styles/socialmedia.inline.style.scss"
          }
        ],
      },
"dev": {
        "fileReplacements": [
          {
             "replace": "src/app/modules/corporate/MainFooter/main-footer-container/socialmedia/styles/socialmedia.style.scss",
                  "with": "src/app/modules/corporate/MainFooter/main-footer-container/socialmedia/styles/socialmedia.inline.style.scss"
          }
        ],
      }
    }

Is there any better way to do it?

Thank you!

1

There are 1 answers

1
Hsuan Lee On BEST ANSWER

Not support now, but multiple configurations will be supported in version 9.x .

By then you can use like this config

{
  "configurations": {
    "production": {...},
    "stage": {...},
    "dev": {...},
    "replaceStyles": {
      "fileReplacements": [
        {
          "replace": "src/app/modules/corporate/MainFooter/main-footer-container/socialmedia/styles/socialmedia.style.scss",
          "with": "src/app/modules/corporate/MainFooter/main-footer-container/socialmedia/styles/socialmedia.inline.style.scss"
        }
      ]
    }
  }
}
$ ng build --configuration=production, replaceStyles
$ ng build --configuration=stage, replaceStyles
$ ng build --configuration=dev, replaceStyles

https://github.com/angular/angular-cli/issues/10612

https://github.com/angular/angular-cli/pull/15819