简体   繁体   English

Angular 进口成本

[英]Angular import cost

I'm working on an angular project.我正在做一个 angular 项目。 I'm trying to reduce the bundle size, so I'm using VS Code Import Cost extension to check the weight that implies each 3rd party library (such as Lodash or RxJS) import.我正在尝试减小包大小,因此我使用VS 代码导入成本扩展来检查暗示每个第 3 方库(例如 Lodash 或 RxJS)导入的权重。

Following best practices I'm changing imports from:遵循最佳实践,我正在更改从以下位置导入的内容: 在此处输入图像描述

To:到:

在此处输入图像描述

As shown in the screenshots, specific imports seems to weight more than generic ones.如屏幕截图所示,特定导入似乎比通用导入更重要。

How is this possible?这怎么可能? Is this because I didn't complete the change in all the files?这是因为我没有完成所有文件的更改吗?

Versions:版本:

  • Angular 9 Angular 9
  • Lodash 4 Lodash 4
  • RxJS 6 RxJS 6

I don't know if this extension works well, but do not use specific imports.我不知道这个扩展是否有效,但不要使用特定的导入。 RxJS was rewritten to work well with es6 module and tree-shaking. RxJS 被重写以与 es6 模块和 tree-shaking 一起工作。

You can use webpack-bundle-analyzer and source-map-explorer to see the details of your bundle.您可以使用webpack-bundle-analyzersource-map-explorer来查看您的包的详细信息。

As for lodash , use lodash-es which works better with tree-shaking至于lodash ,使用lodash-es ,它更适合 tree-shaking

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM