Angular 14 fileReplacements not working for assets with custom webpack builder

Discussão em 'Angular' iniciado por Rich, Agosto 26, 2025.

  1. Rich

    Rich Guest

    I have an Angular 14 application using a custom webpack builder (@angular-builders/custom-webpack:browser) for Module Federation. I want to replace an asset file during the test build, but the replacement doesn’t seem to take effect.

    Here’s the relevant part of my angular.json:

    "build": {
    "builder": "@angular-builders/custom-webpack:browser",
    "options": {
    "outputPath": "target/classes/static",
    "index": "src/index.html",
    "main": "src/main.ts",
    "polyfills": "src/polyfills.ts",
    "assets": [
    "src/favicon.ico",
    "src/assets"
    ]
    },
    "configurations": {
    "test": {
    "fileReplacements": [
    {
    "replace": "src/assets/aws-rum-config.js",
    "with": "src/aws-rum-configs/aws-rum.test.js"
    }
    ],
    "customWebpackConfig": {
    "path": "webpack.config.test.js"
    }
    }
    }
    }


    • src/assets/aws-rum-config.js is an empty placeholder.


    • src/aws-rum-configs/aws-rum.test.js contains the actual test configuration.


    • I run: ng build --configuration=test

    After the build, target/classes/static/assets/aws-rum-config.js is still empty. The replacement doesn’t appear to have happened. I’ve tried adding CopyWebpackPlugin in my custom webpack config to copy the test file, but the file is still overwritten with the placeholder.

    Why is the file replacement not working for an asset inside src/assets/ when using a custom webpack builder, and how can I ensure the correct file ends up in the dist folder?

    What is the order of Angular build? File replacement first before copying of assets or the other way around?

    Continue reading...

Compartilhe esta Página