【问题标题】:Not able to deploy Angular7 app on github pages无法在 github 页面上部署 Angular7 应用程序
【发布时间】:2019-01-15 23:04:38
【问题描述】:

Github 回购:- UI-asset-Agm.

项目名称:- UI-assets 我正在运行以下命令在 github 页面上部署 Angular 应用程序

ng build --prod --base-href "https://skatia.github.io/UI-asset-Agm"



   ngh or 
     npx ngh --dir=dist/UI-assets

但是当我去

 https://skatia.github.io/UI-asset-Agm/ or 
https://skatia.github.io/UI-assets/

它说找不到网站

dist/UI-assets/index.html 是

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>UIAssets</title>
  <base href="https://skatia.github.io/UI-asset-Agm">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://unpkg.com/tachyons@4/css/tachyons.min.css">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<link rel="stylesheet" href="styles.491137759dd7a3a3a7e2.css"></head>
<body>
  <app-root></app-root>
<script type="text/javascript" src="runtime.ec2944dd8b20ec099bf3.js"></script><script type="text/javascript" src="polyfills.1ef83d22ada557f4a131.js"></script><script type="text/javascript" src="main.ca0a7471bf0fe9d8f66d.js"></script></body>
</html>

【问题讨论】:

    标签: angular github-pages


    【解决方案1】:

    假设您的 github 帐户 skatia 有一个名为 ui-asset-agm 的空 git 存储库,并且有一个工作 Angular 6+ 项目 (ng build --prod 运行没有错误)以下应该适合你。


    设置 Angular

    在您的 angular.json 中将以下规则添加(或更新)到您的 configurations/production 条目

    "production": {
      ...
      "baseHref": "/"
      "deployUrl": "https://skatia.github.io/ui-asset-agm"
    }
    

    还将同一文件中的outputPath 更改为docs(默认为dist)。构建与

    ng build --prod
    

    这样做之后,应该有一个名为 /docs 的文件夹,其中包含您成功构建的 Angular 应用程序。如果不是,那么您的 Angular 项目存在一些问题。


    推送到 github

    将您的 github 存储库添加为远程

    git remote add origin https://github.com/skatia/ui-asset-agm
    

    并将其推送到 github

    git push -u origin master
    

    在 github 中转到 repos 设置并选择类似 “使用带有 master/docs 文件夹的 github 页面” 之类的内容。然后您的页面将在

    下可用
    https://skatia.github.io/ui-asset-agm
    

    网站发布需要一些时间,根据我的经验,大约需要一两分钟。

    【讨论】:

    • 在 ng build --prod 之后,我需要做什么?推送到github?我没听懂.....,没有 ngh 命令?
    • 我对 angular.json 进行了更改。然后 ng build --prod 然后 ngh 但没有任何效果
    • 如果运行git push origin master,否则运行git remote add origin https://github.com/skatia/ui-asset-agmgit push -u origin master
    • 我不认为。有支票吗?
    • git remote get-url origin
    猜你喜欢
    • 2020-12-12
    • 2019-03-10
    • 1970-01-01
    • 2021-03-23
    • 2018-12-21
    • 2017-11-03
    • 2021-12-25
    • 2017-07-27
    • 2015-12-15
    相关资源
    最近更新 更多