如何在angular 2中动态加载第三方模块。使用Angular CLI进行生产构建(AOT)。它使用了webpack,它在运行构建命令ng build --prod之后,为早期加载和延迟加载生成了所有构建文件。
我试着使用require js加载第三方模块,webpack已经为第三方模块创建了块js文件,就像懒惰加载的模块一样。然后我使用JIT编译器创建了第三方模块的组件。它对我来说很好。
我正在寻找解决方案,其中第三方模块将提供我编译的组件,我不需要使用Jit创建组件。我正在寻找解决方案,其中将只是动态加载第三方模块,它将开始渲染他们的组件在我的角度2应用程序。
发布于 2020-08-13 14:27:55
我们使用Require JS加载延迟加载的模块。延迟加载模块(sample.module.js)由最终用户放置(在自定义/sampleLib中)。最终用户从他们的应用程序生成延迟加载的模块。将jit编译器导入到我们的系统中,按需创建最终用户的组件。仍然找不到除JiT之外的任何解决方案。
require.ensure(
["assets/samples/sample.module.js"],
(require) => {
let SampleCo = require(assets/samples/sample.module.js");
this._compiler
.compileModuleAndAllComponentsAsync(
SampleCo.SampleCustomModule
).then((compiled) => {
const component1 = compiled.componentFactories.find(
(m) => m.selector == "sample-comp1"
); });
//here we create component with ViewContainerRefr
},
"custom/sampleLib"
}https://stackoverflow.com/questions/50668587
复制相似问题