使用 --base-href 构建 Angular 库

Posted

技术标签:

【中文标题】使用 --base-href 构建 Angular 库【英文标题】:Angular Library build with --base-href 【发布时间】:2020-08-09 20:22:32 【问题描述】:

我有几个自定义 Angular 库,它们将用于 Angular 可运行应用程序。这个可运行的应用程序是使用ng build --deploy-url="dist/" --base-href="appContextPath" 构建的,并使用 maven 插件复制到 war 文件中。

当我使用http://localhost:8080/appContextPath 运行应用程序时,作为可运行应用程序一部分的资产正在加载,但库资产未加载。

我的观察:

1) 开发者工具中的应用资产加载url:

http://localhost:8080/appContextPath/assets/images/search.png

2) 开发者工具中的库资源加载url:

http://localhost:8080/assets/images/xyz.png base-href。

【问题讨论】:

【参考方案1】:

来自angular's documentation:

The <base href> path should end with a "/", as browsers ignore characters in the path 
that follow the right-most "/".

你的情况,试试--base-href="/appContextPath/"

【讨论】:

以上是关于使用 --base-href 构建 Angular 库的主要内容,如果未能解决你的问题,请参考以下文章