如何在Github页面上设置Angular 2的网站

在Angular 2快速入门教程之后 ,我创build了我的网站,并希望它在Github Pages上运行。 但是,我目前通过在terminal中使用npm start命令来运行它。 我必须做出什么样的改变,以便在我将其推送到Github后正确加载?

在我的愚见,Angular2快速启动是一个痛苦,但。 根本不快!

我build议你开始使用Angular2 CLI(命令行工具)。 它快速,易于使用,有一个内置的构build过程 ..你得到一个dist文件夹..等只有优点..

构build过程在这里非常重要,因为如果你想使用gh-pages在GitHub上托pipe你的应用程序,你可以只用一个命令来完成:

 ng github-pages:deploy 

但这是推荐的方法。 在你的情况下,这是不同的。

按照快速入门指南,您没有适当的构build过程,相反,您可以将整个angular2-quickstart文件夹推送到gh-pages分支上的git repo。

首先:安装git,创build一个github账户和一个github仓库。

第二:使用CMD或某个terminal,导航到您的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上托pipe你的应用程序

 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分支上的所有内容都可以在这个urlfind:http: http://your-github-username.github.io/your-repository-name/ 。 就好像它正在加载你的本地主机一样。

你会看到很多文件通过networking调用下载 – 这是因为没有build立过程它的地方 – 没有缩小,没有捆绑,没有任何东西..但工程,我testing了! 所以祝你好运!