Merge fileReplacement attribute of two different angular configurations

Viewed 187

I have a bunch of angular configuration which i use in combination with each other to make different builds but one problem I have is that the fileReplacements attribute of a configs are not merged and the last config given in the build command overwrites the rest of configs' attribute.

Example:

File fileReplacements of config1

{
     "replace": "src/app/tools/white-label.config.ts",
     "with": "src/app/tools/xyz.config.ts"
 }

And fileReplacements of config2

 {
    "replace": "src/app/config/dashboard.config.ts",
    "with": "src/app/config/manage-dashboard.config.ts"
 }

And when i Build with command

ng build --configuration=config1,config2

Only the replacements from config2 apply

1 Answers

The solution would be easy:

in ~/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js

change this section (using Angular 13 around line 150)

for (const configuration of configurations) {
    options = {
        ...options,
        ...(await this.workspaceHost.getOptions(target.project, target.target, configuration)),
    };
}

with this

for (const configuration of configurations) {
    const prevFileReplacements = options.fileReplacements || [];
    options = {
        ...options,
        ...(await this.workspaceHost.getOptions(target.project, target.target, configuration)),
    };
    options.fileReplacements = prevFileReplacements.concat(options.fileReplacements);
}
Related