【问题标题】:How to deploy create-react-app to gh-pages subfolder?如何将 create-react-app 部署到 gh-pages 子文件夹?
【发布时间】:2019-01-25 21:09:23
【问题描述】:

我仍在学习网络开发和课程,所以我为我正在做的每所学校都有单独的存储库。
我在每个大仓库中有很多小项目,在我开始使用create-react-app 之前我没有问题,因为如果没有部署命令清除gh-pages 上的其他项目文件夹,我就无法部署到gh-pages。是否可以以某种方式将其部署到gh-pages 内的子文件夹中?

【问题讨论】:

    标签: github-pages create-react-app


    【解决方案1】:

    gh-pages 有一个-e--dest 选项来指定将所有文件推送到哪个目录。

    ./node_modules/gh-pages/bin/gh-pages.js --help
    

    用法:gh-pages [选项]

    Options:
    
    -V, --version            output the version number
    -d, --dist <dist>        Base directory for all source files
    -s, --src <src>          Pattern used to select which files to publish (default: **/*)
    -b, --branch <branch>    Name of the branch you are pushing to (default: gh-pages)
    -e, --dest <dest>        Target directory within the destination branch (relative to the root) (default: .)
    -a, --add                Only add, and never remove existing files
    -x, --silent             Do not output the repository url
    -m, --message <message>  commit message (default: Updates)
    -g, --tag <tag>          add tag to commit
    -t, --dotfiles           Include dotfiles
    -r, --repo <repo>        URL of the repository you are pushing to
    -p, --depth <depth>      depth for clone (default: 1)
    -o, --remote <name>      The name of the remote (default: origin)
    -v, --remove <pattern>   Remove files that match the given pattern (ignored if used together with --add). (default: .)
    -n, --no-push            Commit only (with no push)
    -h, --help               output usage information
    

    因此,您可以将package.json 更改为具有以下部署脚本。

      "scripts": {
        "predeploy": "npm run build",
        "deploy": "gh-pages -d build -e project-directory-name",
        "start": "react-scripts start",
        "build": "react-scripts build",
        "test": "react-scripts test --env=jsdom",
        "eject": "react-scripts eject"
      }
    

    "deploy": "gh-pages -d build -e project-directory-name", 中,您必须为每个项目指定不同的名称

    【讨论】:

    • 非常感谢!这正是我一直在寻找的 :) 非常感谢!
    • 不客气@Jutzee :)。我也试图解释我解决这个问题的思考过程。希望你能理解。
    • 我知道您是 Stackoverflow 的新手。感谢提出一个好的问题来开始。你做得很好。如果您有任何问题或疑虑,请告诉我们。
    • 如果您有兴趣为开源项目做贡献,请查看我的侧项目First Contributions
    猜你喜欢
    • 2021-09-27
    • 2022-01-20
    • 1970-01-01
    • 2013-07-18
    • 2022-01-23
    • 2020-09-17
    • 1970-01-01
    • 2018-12-09
    • 1970-01-01
    相关资源
    最近更新 更多