簡體   English   中英

如何在Github Pages上使用Angular 2設置網站

[英]How to set up website with Angular 2 on Github Pages

按照Angular 2快速入門教程 ,我創建了我的網站,並希望它在Github Pages上運行。 但是,我目前通過在終端中使用npm start命令運行它。 我必須進行哪些更改才能將其推入Github后正確加載?

以我的拙見,Angular2快速入門是一個令人痛心的事情。 根本不快!

我建議您開始使用Angular2 CLI(命令行工具)。 它快速,易於使用,具有內置的構建過程 ..您會獲得dist文件夾..等。唯一的優勢..

構建過程在這里很重要,因為如果您想使用gh-pages將應用程序托管在GitHub上,則只能使用一個命令來完成此操作

ng github-pages:deploy 

但這是推薦的方法。 就您的情況而言,情況有所不同。

通過遵循快速入門指南,您沒有適當的構建過程,因此可以將整個angular2-quickstart文件夾推送到gh-pages分支上的git repo中。

首先:安裝git,創建一個github帳戶和一個github存儲庫。

第二:使用CMD或某些終端,導航到angular2-quickstart文件夾,然后運行以下命令:

基本設置

git init --> your local, angular2-quickstart folder, becomes a git repository.

git commit -am "messaage: this stuff goes on master branch.."

git remote add origin <your GitHub repository url here> --> this will add the remote url, where you can push and pull.

git push origin master --> your hole folder will be available on GitHub on the master branch

在GitHub上托管您的應用

git checkout -b gh-pages  -> this creates a new branch called gh-pages based of master, and moves you to it.

git commit -am "your commit message" - you must have at least one commit in order to push.

git push origin gh-pages -> this will push the hole gh-pages branch from local repo - to the GitHub repo and hosting servers.

gh-pages分支上出現的所有內容都可以在以下URL上找到:http: http://your-github-username.github.io/your-repository-name/ 就像是從本地主機加載一樣。

您會看到通過網絡調用下載了許多文件-這是因為沒有適當的構建過程-沒有縮小,沒有捆綁,沒有任何東西。。但是可以,我測試了! 祝你好運!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM