问题描述
我正在考虑优化Angular项目,目前正在研究如何使用PrimeNG.Webpack的文档中的摇树"部分( https://webpack.js.org/guides/tree-shaking/)表示,由于无法静态分析CommonJS,因此它依赖ES2015模块格式来确定可以删除哪些代码.
I am looking at optimizing a work Angular project and we're currently looking at how we are using PrimeNG. The Tree Shaking section on Webpack's documentation (https://webpack.js.org/guides/tree-shaking/) says that it relies on the ES2015 module format to determine what code can be pruned away, since CommonJS cannot be statically analyzed.
因此,我假设Angular编译器具有相同的限制,因为它在构建过程中使用Webpack.
So, I assume that the Angular compiler has the same limitation since it uses Webpack on the build process.
话虽如此,我正在查看PrimeNG的安装文档( https://www.primefaces.org/primeng/#/setup ),并声称它以CommonJS格式分发.
That being said, I was looking at PrimeNG's Setup documentation (https://www.primefaces.org/primeng/#/setup) and it claims it is distributed in CommonJS format.
这是否意味着我们在导入单个模块时被迫导入整个PrimeNG?我们可以做些什么来只导入我们需要的东西吗?
Does this mean that we are forced to import the entirety of PrimeNG when we import a single module? Is there something we can do to only import what we need?
最后,有没有一种方法可以在我自己的项目中确定我们是要导入整个PrimeNG还是仅仅是我们需要的?
Lastly, is there a way to determine on my own project if we are importing the entirety of PrimeNG, or just what we need?
谢谢!
推荐答案
如果从已弃用的'primeng/primeng'导入,则可以,整个UI套件都将导入.而是从'primeng/inputtext'或'primeng/tabview'导入,以便只有您需要的东西才会出现在您的捆绑包中.更多信息,请访问以下博客; https://www.primefaces.org/primeng-5-2-0-final-released/
If you import from the deprecated 'primeng/primeng' then yes, whole UI suite is imported. Instead import from 'primeng/inputtext' or 'primeng/tabview' so that only what you need will end up in your bundle. More info at the following blog; https://www.primefaces.org/primeng-5-2-0-final-released/
这篇关于使用PrimePrimeNG时,是将其导入吗?还是摇晃树?我怎样才能自己确定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!