简体   繁体   English

如何加载包含动态惰性模块的 Angular 库?

[英]How to load Angular library which contains lazy modules dynamic?

I am trying to do like this:我正在尝试这样做:

Usually we add a lazy module like this in routing.ts,通常我们在routing.ts中添加一个这样的lazy模块,

{ path: 'taskCenter', loadChildren: './taskCenter/taskCerter.module#TaskCenterModule' }, { path: 'taskCenter', loadChildren: './taskCenter/taskCerter.module#TaskCenterModule' },

now,I want to loadChildren Dynamic from an package which is produced by rollup or ng-packagr !!现在,我想从 rollup 或 ng-packagr 生成的包中加载儿童动态!! Dynamic!动态的!

eg:after Aot build,when url is 'localhost:4200/#/taskCenter',it will dynamic load taskCenter.umd.js and it's child modules from assets folder例如:在 Aot 构建后,当 url 为 'localhost:4200/#/taskCenter' 时,它将动态加载 taskCenter.umd.js 及其资产文件夹中的子模块

First,how can we package all lazy modules in library?首先,我们如何将库中的所有惰性模块打包? Then,how to load this module dynamic?那么,如何动态加载这个模块呢?

 // First, in Library ,how to package all code including TestChildrenModule @NgModule({ imports: [ RouterModule.forChild([ { path: '', pathMatch: 'full', component: ModuleaComponent }, { path: 'aa', loadChildren: './test-children/test-children.module#TestChildrenModule' } ]) ], declarations: [ModuleaComponent], exports: [ModuleaComponent] }) export class ModuleaModule { }

this link maybe can help: https://github.com/lmeijdam/angular-umd-dynamic-example此链接可能会有所帮助: https : //github.com/lmeijdam/angular-umd-dynamic-example

Lazy loading should happen at an application and not a library level延迟加载应该发生在应用程序而不是库级别

From this disscussion: article link来自本次讨论:文章链接

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

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