相关疑难解决方法(0)

如何将Angular Elements与“ ng g库”方法混合使用?

如您所知,“ ng g库”方法可帮助我们创建可重用组件的库。但是,如果我希望通过Angular Elements的支持将那些组件编译为Web组件呢?不仅如此,库中的每个组件都将被编译到其自己的文件夹或JS文件中。如何配置一个开发环境以实现这一目标?

例如:

如果创建一个Lib并添加一个自定义组件,我知道我可以对其进行编译,生成一系列文件夹,例如esm5,esm2015,fesm5等。现在,问题是:如何添加,比如说30个自定义组件到我的库中,然后在编译时,它将为每个组件创建一个文件夹,其中包含它们的Web组件版本...仿佛Angular Elements遍历了我的组件库并生成了每个组件的Web组件版本。

像这样:

lib/
lib/custom/comp1
lib/custom/comp2
lib/custom/comp3
lib/custom/comp4
Run Code Online (Sandbox Code Playgroud)

变成类似以下内容:

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
Run Code Online (Sandbox Code Playgroud)

我找到的最接近的解决方案是这样的:

https://medium.com/@rahulsahay19/running-multiple-angular-elements-on-the-same-page-5949dac5523

我还要求Angular CLI团队提供帮助:

https://github.com/angular/angular-cli/issues/13999

angular-cli angular ng-packagr angular-elements

20
推荐指数
1
解决办法
946
查看次数