Angular部署在GitHub Pages上

4

我想将一个Angular应用程序部署到GitHub页面,但是将gh-pages分支设置为源时,会显示README文件的内容。

我已经尝试了官方推荐的方法:

git checkout -b gh-pages
git push origin gh-pages
npm install -g angular-cli-ghpages
ng build --prod --base-href https://[username].github.io/[repo]/

运行ngh后,终端会显示以下信息:

User@JoseTurron MINGW64 /i/projekt-zaliczeniowy-cdv (gh-pages)
$ ngh
index.html could not be copied to 404.html. This does not look like an angular-cli project?!
(Hint: are you sure that you have setup the directory correctly?)
Diagnostic info: ENOENT: no such file or directory, stat 'I:\projekt-zaliczeniowy-cdv\dist\index.html'
�‍� Uploading via git, please wait...
� Successfully published via angular-cli-ghpages! Have a nice day!

我已经没有任何解决这个问题的想法了,感谢任何建议!

2个回答

4

以下是如何将Angular应用程序部署到Github Pages的详细步骤指南。

1) git init //用于初始化git,使用cmd/shell命令并按Enter键

2)git add . //将所有文件添加到git中

3)git commit -m "first commit" //对提交进行描述的消息

4)git remote add origin "你的远程存储库url" //连接到git repo

5)git push -u origin master //推送到git repo

6)npm install -g angular-cli-pages //安装angular pages以便在Github Pages上部署Angular项目

7)ng build --prod --base-href="https://Username.github.io/github-Repo/" //生成ghpages生产版本

*8)完成以上步骤后,转到项目文件夹,里面会有一个dist文件夹,进入dist>YOurProjectFolder->将所有文件移动到上一级目录*

9)angular-cli-ghpages //部署ghpages

10) 转到github repo设置,向下滚动,会看到Github Pages和您发布的repo链接,单击即可在ghPages上启用Angular应用程序


3
解决方案如下:
ng add angular-cli-ghpages
ng deploy --base-href=https://[username].github.io/[repo]/ --name=[username] --email=[email]

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接