【问题标题】:Angular 10 --deploy-url assets path in IISIIS 中的 Angular 10 --deploy-url 资产路径
【发布时间】:2020-12-06 08:21:39
【问题描述】:

在我从版本 7 升级到 Angular 10 后,assets 文件夹的字体和图像未在浏览器中加载并出现 404 错误。

http://localhost/assets/fonts/Regular/OpenSans-Regular.woff?v=1.1.0 net::ERR_ABORTED 404(未找到)

我将我的 Angular 应用程序托管在 IIS 的子目录中,并使用 --deploy-url--base-href 开关来构建我的应用程序。

我的构建命令:

ng build --prod --base-href /MyApp/ --deploy-url /MyApp/Scripts/

Scripts 文件夹包含构建命令的所有输出。 我将组件内的图像称为:

background-image: url(/assets/images/login_bg.png);

并将字体称为:

@font-face {
   font-family: 'Open Sans';
   src: url('/assets/fonts/Regular/OpenSans-Regular.eot?v=1.1.0');
   src: url('/assets/fonts/Regular/OpenSans-Regular.eot?#iefix&v=1.1.0') format('embedded-opentype'), 
   url('/assets/fonts/Regular/OpenSans-Regular.woff?v=1.1.0') format('woff'), 
   url('/assets/fonts/Regular/OpenSans-Regular.ttf?v=1.1.0') format('truetype'), 
   url('/assets/fonts/Regular/OpenSans-Regular.svg?v=1.1.0#Regular') format('svg');
   font-weight: normal;
   font-style: normal;
}

我注意到 Angular CLI 7 和 Angular CLI 10 中的构建输出不同。 在这里我们可以看到,使用 Angular 7 我们有正确的路径来定位 Web 服务器中的图像,但在 Angular 10 中我们只有部分路径会导致 404 错误。

请提出建议。

【问题讨论】:

  • 这里也一样。找到解决方法了吗?

标签: angular angular-cli angular10


【解决方案1】:

github 登录了同样的问题

基本上推荐的解决方案是使用从组件文件夹到根级assets文件夹的相对路径../

【讨论】:

    猜你喜欢
    • 2019-04-07
    • 2018-10-05
    • 2012-02-07
    • 2022-06-10
    • 1970-01-01
    • 2018-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多