javascript - 如何在 Github Pages 上使用 Angular 2 建立网站

标签 javascript node.js angular github-pages

Angular 2 quickstart tutorial 之后,我已经创建了我的网站并希望它在 Github Pages 上运行。但是,我目前通过在终端中使用 npm start 命令来运行它。我必须进行哪些更改才能在将其推送到 Github 后正确加载?

最佳答案

在我看来,Angular2 快速入门是一个痛苦的地方。一点都不快!!

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

构建过程在这里很重要,因为如果您想使用 gh-pages 在 GitHub 上托管您的应用程序 - 您只需一个命令即可:

ng github-pages:deploy 

但这是推荐的方式。就您而言,情况有所不同。

按照快速入门指南,您没有适当的构建过程,因此您可以将整个 angular2-quickstart 文件夹推送到 gh-pages 分支上的 git 存储库。

首先:安装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://your-github-username.github.io/your-repository-name/。它与从您的本地主机加载的内容相同..

您会看到通过网络调用下载了很多文件 - 这是因为它没有构建过程 - 没有缩小,没有捆绑,什么都没有..但是有效,我测试了它!祝你好运!

关于javascript - 如何在 Github Pages 上使用 Angular 2 建立网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39188025/

相关文章:

javascript - POST 方法后清除所选值

javascript - Multiple Item 轮播(JS转TS文件)

javascript - Node.js module.exports 与文件系统

javascript - 如何使用结构指令?

javascript - 创建可滚动的滑动页面

javascript - knockoutJS $index 无法正常工作

ios - 是否可以在 iOS 应用程序中热交换 ionic 代码?

c# - ASP.NET Core 2 MVC + EF Core 2 或 Angular 5

node.js - NodeJs - Sequelize - 无法识别的属性数据类型

javascript - 为什么 console.log 显示错误属性?