Differential builds with Ionic-v4 - exclude unnecessary dependencies


We have some classes (services/providers) that are specific for Android only and we would like to not include them when building our PWA or our iOS app. Similarly, we do not require any of the Cordova dependencies / Ionic native libraries when building the Progressive Web App.

How is it possible to create differential builds so that PWA, Android and iOS builds do not include exactly the same source code?

We currently have interfaces for the platform specific classes and we manually comment out the Android implementations when building PWA and manually include PWA implementation stubs. We currently do that in the app module providers array. This gets very cumbersome the more differential the builds get.

Perhaps the providedIn mechanism in Angular could be used somehow to achieve non-manual tree-shaking: https://offering.solutions/blog/articles/2018/08/17/using-useclass-usefactory-usevalue-useexisting-with-treeshakable-providers-in-angular/

This question is similar to the one asked about 3 years ago here: Build & Serve ionic as a web app

1 Like