'How to ignore a module in angular production build with optimisation flag set to true

I am working on an angular 8 WebRTC app in which I am using rainbow web sdk node module. The problem I have is if I build the solution with the flag --optimization=true to get the bundle size optimized; then it gives the following error.

Uncaught Error: [$injector:unpr] http://errors.angularjs.org/1.7.5/$injector/unpr?p0=webConferenceServiceProvider%20%3C-%20webConferenceService%20%3C-%20conversationService%20%3C-%20botService%20%3C-%20connectionService%20%3C-%20rainbowSDK

But, if I set the flag --optimization=false then it works and the bundle size increases significantly which is not good for production.

The SDK is written in AngularJS 1.7.5 that I have included as a dependency on the index.html page. I had a discussion with the SDK developer and he confirmed to me that the SDK runs an angularJS app. If I use the optimization flag in my project; it mangles the module name which is why the SDK doesn't work.

He suggested not to optimize the build. But then I have a huge bundle size that is not compressed and minified.

I have tried custom webpack configuration to ignore the SDK import in production build optimization but still, the SDK gets modified and shows the same error in console while browsing the application.

Question: What can be done to ignore the 'mangling' of rainbow-web-sdk module in ng build --prod with --optimization=true to get an optimized bundle at the output?

I have the following configuration in the angular.json file for a production build.

"build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
        "outputPath": "dist",
        "index": "src/index.html",
        "main": "src/main.ts",
        "tsConfig": "src/tsconfig.json",
        "polyfills": "src/polyfills.ts",
        "assets": [
            "src/assets"
        ],
        "styles": [],
        "scripts": []
    },
    "configurations": {
        "production": {
            "optimization": false,
            "outputHashing": "all",
            "sourceMap": false,
            "extractCss": true,
            "namedChunks": false,
            "aot": true,
            "extractLicenses": true,
            "vendorChunk": false,
            "buildOptimizer": true,
            "fileReplacements": [{
                "replace": "src/environments/environment.ts",
                "with": "src/environments/environment.prod.ts"
            }]
        }
    }
}

To try out, here is a github sample angular 8 app uploaded by the sdk developer.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source