如何将 create-react-app 部署到 gh-pages 子文件夹?
How to deploy create-react-app to gh-pages subfolder?
我仍在学习网络开发和课程,所以我为我正在做的每所学校都有单独的回购协议。
我在每个大仓库中都有许多小项目,这在我开始使用 create-react-app
之前没有问题,因为如果没有它的部署命令清除 gh-pages
上的其他项目文件夹,我无法部署到 gh-pages
.是否可以通过某种方式将其部署到 gh-pages
中的子文件夹中?
gh-pages
有一个 -e
或 --dest
选项来指定将所有文件推送到哪个目录。
./node_modules/gh-pages/bin/gh-pages.js --help
Usage: gh-pages [options]
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",
中,您必须为每个项目指定不同的名称
我仍在学习网络开发和课程,所以我为我正在做的每所学校都有单独的回购协议。
我在每个大仓库中都有许多小项目,这在我开始使用 create-react-app
之前没有问题,因为如果没有它的部署命令清除 gh-pages
上的其他项目文件夹,我无法部署到 gh-pages
.是否可以通过某种方式将其部署到 gh-pages
中的子文件夹中?
gh-pages
有一个 -e
或 --dest
选项来指定将所有文件推送到哪个目录。
./node_modules/gh-pages/bin/gh-pages.js --help
Usage: gh-pages [options]
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",
中,您必须为每个项目指定不同的名称