首页 > 解决方案 > 如何在同一目录中的文件中指定路径?

问题描述

<base href="/" />在 index.html 文件的顶部。

下面我尝试将加载文件放在同一个目录下:

<link rel="stylesheet" href="styles.43ad38c1c1e1ce781d48.css">

结构目录为:

/site/
/site/index.html
/site/styles.43ad38c1c1e1ce781d48.css

标签: angularangular7

解决方案


您可以通过 angular.json 中项目的构建目标选项中的样式选项添加更多全局样式。这些将完全加载,就像您将它们添加到 index.html 内的标记中一样。

"architect": {
  "build": {
    "builder": "@angular-devkit/build-angular:browser",
    "options": {
      "styles": [
        "src/styles.css",
        "src/more-styles.css",
      ],

参考:https ://github.com/angular/angular-cli/wiki/stories-global-styles


推荐阅读