代码如下:
ConfigModule.withConfig({ cmsComponents: { SimpleResponsiveBannerComponent: { component: () => import('./lazy/lazy-banner.component').then( (m) => m.LazyBanner ), } } }),
这样,ng build时,builder不会将lazy-banner.component.ts打包到main chunk里,而是生成一个单独的chunk:lazy-lazy-banner-component, 如下图所示:
在运行时,main chunk和lazy-lazy-banner.component.js这两个chunk也会分别加载:
参考文档:
https://sap.github.io/spartacus-docs/lazy-loading-guide/
专门的lazy load modules实现:
lazy-modules.service.ts