Can we use multiple libraries in angular(2/4/5/6) because it supports TreeShaking ? Without hitting the performance and build size

你说的曾经没有我的故事 提交于 2020-01-15 09:42:08

问题


I have gone through this article : https://www.reddit.com/r/Angular2/comments/6a678s/primeng_vs_material2/ In the comment they mentioned we can use Prime Ng and Angular material together in app. In PrimeNg components are standalone modules mostly so you can add only the ones you need and same is true for Angular material after couple of updates.

My question is... Can we use multiple number of libraries as many as we want with Angular app Like: PrimeNg, Angular material, Fuse and many more. Without affecting the performance or size of the build, because Tree shaking will take care of it. Basically I want to use Material only for designing layout and some look and feel that.

Also, Does angular(5/6) supports 100% tree shaking or still we need to use Rollup.js ? Gone through multiple article but not sure yet.


回答1:


When you build an Angular app with production flag, every component, service, directive or pipe is referenced at least once (in @NgModule annotations). At the end of the AOT compilation, the compiler removes these annotations and after that it also removes unreferenced things.

Source

That said, every Angular Material component is a module, which gives you fine grained import of the library.

I don't know PrimeNg, but from what I quickly searched and as you already know it seems to have one module per component too.

Using both libraries should not affect bundle size nor performance, but you should be aware that the "look and feel" differs from UI library to UI library



来源:https://stackoverflow.com/questions/51043663/can-we-use-multiple-libraries-in-angular2-4-5-6-because-it-supports-treeshakin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!