共享模块中未使用的组件会降低我的应用程序速度吗? [英] Do unused components in shared modules slows down my application?

查看:46
本文介绍了共享模块中未使用的组件会降低我的应用程序速度吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的电子组件中,我导入了shared.module(具有brand-brand.component,product-list.components等),并且还导入了我在其他类别(视频游戏,玩具等)中的共享模块.导入它们时,我的shared.modules中的某些组件未使用.共享模块中这些未使用的组件会降低我的应用程序速度吗?在此先多谢.

In my electronic component, I import my shared.module(has featured-brand.component, product-list.components, etc) and also I import my shared modules in my other categories (video games, toys, etc). Some of the components in my shared.modules are not used when I import them. Will these unused components in my shared module slows down the my application? Thanks a lot in advance.

推荐答案

条件减慢"很难量化.不过,要回答您的问题,了解一下模块中的实际作用是很有帮助的. :

The criteria "slow down" is difficult to quantify. To answer your question though, it's helpful to understand what declaring components in a module actually does:

NgModule是一个用@NgModule元数据修饰的类.元数据执行以下操作:

An NgModule is a class decorated with @NgModule metadata. The metadata do the following:

  • 声明哪些组件,指令和管道属于该模块.

仅声明您的组件不会对性能产生有意义的影响.它只是使Angular意识到它们的存在,因此可以将它们与您的组件选择器进行匹配.

Simply declaring your components there won't meaningfully affect performance. It just makes Angular aware of their existence, so they can be matched to your component selectors.

但是,这带来了一个巨大的警告-如果您在生产中使用Angular进行典型的构建过程,则您在模块上声明的组件将被捆绑在输出JavaScript中(它们不会被删除)摇树).通常,这是正确的行为(因为某些组件仍在使用您的组件).但是,如果您是延迟加载,并且性能至关重要,则需要确保不会将不必要的组件打包到包中.

However, this comes with a huge caveat - if you're using Angular in production with a typical build process, the components that you declare on your modules are going to be bundled in your output JavaScript (they won't be removed by tree-shaking). Typically this is the correct behavior (as your component is still being used by some things). If you're lazy-loading, however, and performance is critical, you'll want to make sure that you aren't packing unnecessary components into your bundles.

这篇关于共享模块中未使用的组件会降低我的应用程序速度吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆