Reputation: 335
We are building an Angular application that should have the capability of discovering and dynamically loading custom libraries, i.e. the libraries that are not known/available at build time.
To support that, we cannot tree-shake the main application since these custom libraries can use symbols from third-party libraries (e.g. angular, rxjs) that the main application does not.
What would be the way to solve it with angular-cli v6? Is there a way to disable tree-shaking in the production build?
Upvotes: 2
Views: 2765
Reputation: 2278
I think the tree shaking process is part of the angular-cli AOT build feature, but the documentation itself does not give a lot of information about how exactly this is done and weather or not you can enable/disable this feature. As far as I'm concerned, there is no straight forward way to just disable tree shaking within the angular-cli. The cli documentation states the following:
All builds make use of bundling and limited tree-shaking, while --prod builds also run limited dead code elimination via UglifyJS.
So this seems to be pretty much hooked into AOT. Disabling tree shaking is probably also contrary to what the angular-cli has been trying to achieve with its building options for the last year or so, mainly to make it an easy to use tool to decrease angular's bundling sizes.
The angular-cli provides some options to adjust the building, but for the tree shaking part, I guess you either have to go with it somehow, or, if not possible, you probably have to dig a lot deeper and try to create your own build with something like webpack (which the cli uses underneath its hood I think). You can adjust pretty much everything there. This freedom of course comes with the cost of an increased time investment to create an efficient build that is comparable to angular's build
command.
Upvotes: 1