如何将创建-反应-应用程序部署到 gh-pages 子文件夹?



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

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

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

用法: gh-页 [选项]

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",,您必须为每个项目指定一个不同的名称

最新更新