Angular CLI: 發佈到 GitHub Pages

發佈 Angular 應用的簡單方式是使用 GitHub Pages.javascript

點擊這裏 能夠查看發佈以後的應用。css

 

首先須要建立一個 GitHub 帳號,隨後,爲您的項目建立一個倉庫。記下 GitHub 中的用戶名和項目名稱。html

例如,個人 GitHub 帳號是 haoguanjun,我建立的項目名稱是 ng-hello。java

而後,您要作的就是運行 git

ng build --prod --output-path docs --base-href ng-hello

這個 PROJECT_NAME 就是您的項目在 GitHub 中的名稱。這個示例中使用的項目名稱是 ng-hello,將 docs/index.html 複製爲 docs/404.html。github

提交修改並 Push 到倉庫中。app

您應該在項目的主頁 https://github.com/haoguanjun/ng-hello 上,看到一個 docs 的文件夾,其中包含了一個 404.html 頁面。ui

頁面內容以下所示:spa

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Hello</title>
    <base href="ng-hello">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link rel="icon" type="image/x-icon" href="favicon.ico">
    <link href="styles.d41d8cd98f00b204e980.bundle.css" rel="stylesheet"/>
  </head>
  <body>
    <app-root></app-root>
    <script type="text/javascript" src="inline.97a5517db35cb02cdd8d.bundle.js"></script>
    <script type="text/javascript" src="polyfills.f20484b2fa4642e0dca8.bundle.js"></script>
    <script type="text/javascript" src="main.352a0febf476a50f1de9.bundle.js"></script>
  </body>
</html>

 

在 GitHub 項目的頁面上,配置爲 publish from the docs folder.code

點擊項目中的 ,進入項目配置頁面。找到 GitHub Pages 配置部分。

在 Source 下面的下拉列表中,找到 master branch/docs folder ,選中並保存。以下所示。

 

這就是全部您須要作的!如今能夠訪問地址 https://USER_NAME.github.io/PROJECT_NAME 來訪問頁面了。

這個示例的寄宿在 GitHub 的 https://haoguanjun.github.io/ng-hello/ 中,能夠直接點擊查看。

這個示例全部的代碼都保存在 https://github.com/haoguanjun/ng-hello 中,您能夠直接下載查看。

您還能夠使用 angular-cli-ghpages,這是一個全功能的包,能夠幫助您作全部這些工做,且還有額外的功能。

相關文章
相關標籤/搜索