ng build --prod --base-href

8

ng build --prod --base-href /gi-new --deploy-url /gi-new

我将 Angular 5 应用部署到了 Windows 共享 IIS 服务器上。

我已经上传了 dist 文件夹中的内容到 http://192.168.10.181/gi-new

我的应用程序可以运行,但是 assets 中的图标没有选择正确的路径,因此它们在网页上不显示。

它们使用的是 http://192.168.10.181/assets 而不是 /gi-new/assets

angular-cli.json 中的条目

"assets": [ {
    "glob": "*.svg",
    "input": "../node_modules/material-design-icons/sprites/svg-sprite/",
    "output": "assets/svg-icons"
}]

AppComponent中的条目

constructor(iconRegistry: MatIconRegistry, sanitizer: DomSanitizer) {
    iconRegistry.addSvgIconSetInNamespace
    ( "action", sanitizer.bypassSecurityTrustResourceUrl("assets/svg-icons/svg-sprite-action.svg"));

我该如何解决这个问题?
2个回答

0

我遇到了相同的问题,需要手动提供正确的路径来访问所有来自资产文件夹(在生产模式下打包的文件)中的图标或.gif、.jpg等文件。

例如,如果你有一个类似于https://ip_address_name/gi-new的路径,你需要在生产打包文件的每个地方添加(/gi-new/assets/your_icon_name)。

这是解决这个特定问题的一种方法。


-1

问题已经被我自己解决了。 只需要在环境配置文件中添加一个baseHref的条目,并在“assets/svg-icons”之前添加对应的值即可。


4
你能详细说明你的回答吗? - Shekhar Sahu
你添加了什么?有哪些更改?请详细说明。 - Tanzeel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接