如您所知,“ng g library”方法可以帮助我们创建可重用的组件库。但是,如果我想将这些组件编译为 Web Components,通过 Angular Elements 的支持呢?而且每个来自 lib 的组件都要编译到自己的文件夹或 JS 文件中。如何配置开发环境,以使我能够实现这一点?
例如:
如果我创建一个 Lib 并添加自定义组件,我知道我可以编译它,生成一系列文件夹,例如 esm5、esm2015、fesm5 等。现在问题是:我如何向我的 lib 中添加 30 个自定义组件,然后在编译时,它将为每个组件创建一个文件夹,其中包含它们的 Web Component 版本……就好像 Angular Elements 经过我的组件库并为它们中的每一个生成了 Web Component 版本。
像这样:
lib/
lib/custom/comp1
lib/custom/comp2
lib/custom/comp3
lib/custom/comp4
变成类似于下面的内容:
Dist/
Dist/custom/
Dist/custom/bundle
Dist/custom/esm5
Dist/custom/esm2015
Dist/custom/comp1_web_independend_component_version
Dist/custom/comp2_web_independend_component_version
Dist/custom/comp3_web_independend_component_version
Dist/custom/comp4_web_independend_component_version
我找到的最接近的解决方案是这个:
https://medium.com/@rahulsahay19/running-multiple-angular-elements-on-the-same-page-5949dac5523
我也请求了 Angular CLI 团队的帮助: