项目部署
项目部署于github pages
上,可以参照cra的部署教程。此次的部署过程略有不同:
因部署于github,所以需要先在pakcage.json
上配置homepage
指向项目的预览地址跟路径。
{
"name": "fingertips-book-react",
"private": true,
"homepage": "https://untilthecore.github.io/fingertips-book-react-website/",
"scripts": {
"start": "node scripts/start.js",
"build": "node scripts/build.js",
"auto_build": "sh scripts/deploy.sh"
}
}
在script
目录下创建deploy.sh
自动部署脚本:
#!/usr/bin/env bash
# 请确保执行目录为项目根目录
yarn build &&
cd build &&
git init &&
git remote add origin git@github.com:UntilTheCore/fingertips-book-react-website.git &&
git add . &&
git commit -m 'deploy' &&
# 由于github默认分支更改为 main,所以需要执行一次分支改名
git branch -M main
# 可能遇到推送失败,加 -f 参数执行强制推送
git push -u origin main -f &&
cd .. &&
echo "部署完成"
在根目录下执行yarn auto_build
即可实现自动部署。