我一直在尝试将我的angular 2应用程序部署到github页面,这样我就可以在托管的github链接上查看应用程序,但到目前为止还没有运气。
一旦我完成了我的应用程序,我就运行了这些命令:
ng build --prod
git remote add origin "My REPO"
git commit -a
git push -u origin master
然后我试着在终端上运行
ng github-pages:deploy
并得到此错误:
The specified command github-pages:deploy is invalid. For available options, see `ng help`.
经过研究,我跑过这个页面并按照说明:https://www.npmjs.com/package/angular-cli-github-pages
我在项目目录中通过npm安装了angular-cli-github-pages:
npm install --save-dev angular-cli-github-pages
它说我必须创建gh页面,所以我运行以下命令:
git checkout --orphan gh-pages
然后提交文件并推送更改并返回到原始主服务器并运行deploy命令,它给了我同样的错误:
The specified command github-pages:deploy is invalid. For available options, see `ng help`.
我一直在用不同的方法来回走动,但它不起作用。有人可以指出我应该做什么来正确部署到github页面?
我最近遇到了同样的问题。在对angular2社区进行了几个小时的搜索之后,我发现在最新的angular-cli版本中已经删除了angular-cli-github-pages模块。要将Angular 2应用程序部署到gh页面,您现在需要安装一个新的npm模块,它与旧的angular-cli-github-pages模块非常相似,但是可以让您比以前的模块做更多的工作。
npm模块是angular-cli-ghpages。您可以在模块的npmjs页面上找到文档和步骤。
希望这对你有所帮助。
在First安装angular-cli ghpages
npm install -g angular-cli-ghpages
安装下一步后,链接您的存储库。运行此命令
ng build --prod --base-href "https://<user-name>.github.io/<repo>/"
如果您看到错误然后省略--prod并运行此命令
ng build --base-href "https://<user-name>.github.io/<repo>/"
您现在可以在angular 2 app目录中看到dist文件夹。
上传github存储库中dist文件夹的所有文件。
然后从设置启用Github页面。我们将为您提供一个链接。
而已。
但是:ぁzxswい
我发现部署到Github Pages的最简单方法是使用master分支或master分支中的doc作为Settings中的source选项。我选择master分支选项中的文档,并将docs文件夹视为构建目录。它工作得很好。我只是推送到掌握,Github检测到docs文件夹,然后创建包含其内容的app / page。
要将Angular应用程序部署到Github,请执行以下步骤:
控制台将显示如下内容:
https://github.com/
这会将您的本地dist文件夹推送到名为“gh-pages”的分支到您的Github存储库中。然后在您的Github存储库中,单击Settings,转到GitHub Pages部分,然后在下拉选择器中选择“gh-pages branch”。
注意:下次进行更改并希望部署应用程序时,请执行步骤2和3.请注意,需要花费一些时间(分钟)来刷新Github中的更改。