1

我目前正在测试一个 Angular 应用程序/Java 微服务后端,并将前端部署在 Gitlab Pages 上。

到目前为止, gitlab-ci.yml 非常简单,因为我只是在测试架构:

cache:
  paths:
    - node_modules/

stages:
  - staging
  
pages:
  image: node:latest
  stage: staging
  script:
    - npm install -g @angular/cli@11.0.1
    - npm install
    - ng build --prod
  artifacts:
    paths:
    - public

我将 angular.json 更改为输出 public/ 而不是 dist/。该站点在地址https://myaccount.gitlab.io/repository-name上部署得很好,但只有 index.html 有效。

原因是,里面的所有 href 都有些错误:

<script src="runtime.0e49e2b53282f40c8925.js" defer></script>
<script src="polyfills.e6e62ba5ee83d54cee93.js" defer></script>
<script src="main.26f4db6ed1e6241cbf51.js" defer></script>

href 指向https://myaccount.gitlab.io/runtime.0e49e2b53282f40c8925.js而不是https://myaccount.gitlab.io/repository-name/runtime.0e49e2b53282f40c8925.js,所以我所有的裁判都会抛出 404 错误

有谁知道为什么会这样,以及如何解决?多谢 !

4

1 回答 1

0

很抱歉给您带来不便,我为自己的问题找到了一个非常简单的答案,所以我会在这里发布以防有人需要。

可以简单地更改角度构建的 base-href

--base-href /your-path/

所以我只是像这样改变了我的 ng 构建:

- ng build --prod --base-href /croquis-time-client/
于 2021-09-14T22:11:38.183 回答