【问题标题】:how to publish to github pages?如何发布到 github 页面?
【发布时间】:2018-06-13 13:58:02
【问题描述】:

我无法理解一些关于发布到 github 页面的基本说明。有一种新方法可以发布使用 Angular Cli 制作的 Angular 项目;我正在遵循this page 的新命令angular-cli-ghpages 的指示:

Execute angular-cli-ghpages in order to deploy the project with a build from dist folder.
Note: you have to create the dist folder in before (e.g. ng build --prod)

Usage:

ng build --prod --base-href "https://USERNAME.github.io/REPOSITORY/"
angular-cli-ghpages [OPTIONS]

我为我的项目创建了一个 dist 文件夹,然后运行 ​​ng 构建代码。终端显示所有块都已呈现,但我找不到 github 页面的链接。我在 github 上查看我的存储库,好像什么都没发生。这是因为我需要 cd 到一个特定的文件夹来执行 angular-cli-ghpages 吗?这是我的repo,非常感谢任何帮助。

【问题讨论】:

    标签: angular angular-cli github-pages


    【解决方案1】:

    我可以使用命令成功推送到 github 页面

    angular-cli-ghpages --repo=https://github.com/parthghiya/testrepo.git --name=parthghiya --email=parth.ghiya@knowarth.com --no-silent
    

    回购链接:https://github.com/parthghiya/testrepo

    我做了ng build --prod --base href .

    我做过的步骤:

    1. 生成了我的 SSH 并添加了它。

    https://help.github.com/articles/connecting-to-github-with-ssh/

    1. 执行了推送命令。

    编辑:

    添加多个文件夹

    创建与资产平行的文件夹,我创建了 2 个文件夹 Parth 和 Ghiya。然后在 angular-cli.json

    中添加以下条目
    "assets": [
            "assets","parth","ghiya",
            "favicon.ico",
            "manifest.json"
          ],
    

    所以 dist 文件夹现在包含 3 个文件夹,现在是 assets,parth 和 ghiya。 然后像之前一样执行上面的推送命令。

    【讨论】:

    • 我发布到 github 页面,但只显示 index.html 文件:github.com/st4rgut25/biopage。您如何使用 angular-cli-ghpages 命令将文件夹和子文件夹推送到存储库中?谢谢,感谢您迄今为止的帮助。
    • @st4rgut:不客气 :),请检查编辑并告诉我是否有帮助。
    • 谢谢,但我在修改 angular-cli.json 后仍然无法推送子目录。我尝试将文件 src 添加到资产中。详情请查看我的编辑
    • @st4rgut :但这些是您的开发文件夹。只有要推送的内容是 dist 文件夹的内容。除了 dist 文件夹的内容之外,GitHub 页面不需要任何内容​​。
    • 所以我应该能够在不将src 文件推送到存储库的情况下托管我的页面?
    【解决方案2】:

    删除了通过 angular cli 部署到 github 的选项。

    See this change

    【讨论】:

    • 我相信您指的是github-pages:deploy 命令?据我了解,`angular-cli-ghpages' 已取代旧命令,该命令不再有效
    • 我很抱歉....你是对的,我指的是 CLI 中内置的旧命令,该命令已被删除
    【解决方案3】:

    试试这个(对于 mac):

    1. $ npm install -g angular-cli-ghpages

    2. 将您的代码推送到 github 存储库,然后在终端中运行:ng build --env=prod --base-href "https://yourgithubusername.github.io/yourprojectname/" 此处 'yourprojectname' 是您的 github 存储库的名称,而不是您的本地名称 回购。

    3. 如果一切正常,则运行:sudo angular-cli-ghpages 并输入密码。

    【讨论】: