Angular 模块导入它不使用的模块的潜在缺点?

Potential drawbacks of Angular module importing modules it doesn't use?

假设在我的 Angular 应用程序中有一个 NgModule,我想向它的 imports 数组添加一堆模块。我不想单独导入每个模块,而是将模块收集到一个组中并导入整个组。组中的一些模块实际上对该 NgModule 有用,其他模块则没有。

导入特定模块实际未使用的模块可能有哪些缺点?请注意,每个导入的模块仍在应用程序中某处使用,只是在该特定模块中不需要它们。

例如,让我们考虑一个包含通用输入组件模块的 index.ts 文件,可在路径 @app/common/inputs:

中找到
// whatever imports are necessary

const Modules = [
  TextBoxModule,
  SelectModule,
  DatePickerModule,
  // etc.
];

// export individual module types and the Modules array

我有 MyWonderfulComponent,它使用 TextBoxComponent 和 DatePickerComponent(分别使用 TextBoxModule 和 DatePickerModule)。但是,它不使用任何其他输入组件(包括 SelectComponent)。

尽管如此,作为一个懒惰的软件工程师,我将所有输入模块导入 MyWonderfulModule,因为它需要 1 行而不是仅导入 TextBoxModule 和 DatePickerModule 的 2 行:

// some basic imports
import * as Inputs from '@app/common/inputs';

@NgModule({
  declarations: [
    MyWonderfulComponent
  ],
  imports: [
    ...Inputs.Modules,
    // etc.
  ],
  exports: [
    MyWonderfulComponent
  ]
})
export class MyWonderfulModule {
}

除了非常需要的 TextBoxModule 和 DatePickerModule 之外,导入不需要的 SelectModule(和一堆其他输入模块)有什么缺点?

它是否有任何显着的性能或内存占用?它会导致更长的编译过程 and/or 更大的输出文件吗?或者也许不需要的导入是 "just there" 并且对应用程序没有重大影响?

(记住 - 所有输入模块都在 某处使用 - 只是 MyWonderfulComponent 除了文本框和日期选择器之外没有使用任何东西)

已导入但未使用的模块已从您的 Angular 应用程序的生产版本中删除,因此它根本不会影响生产性能。

话虽如此,如果该模块中未使用它们,我建议将它们从该模块的 imports 数组中删除,以保持代码简洁明了。