本文常识简略的前端我的项目的部署,不波及后盾。
以 github action 为例 (CI/CD)
目前暂定我的项目为 demo (可自行调整)

环境

node 装置 (留神如果是 mac M1 的。版本固定装置为 14.17.0)

本地创立我的项目

npx create-react-app demo

github 创立 repository

创立名称为 demo

配置 Github 的公私钥

私钥在本地,公钥能够调配配置在 github上

本地代码提交到 github 上

git initgit add .git commit -m 'a'git remote add origin git@github.com:huiminxu/demo.gitgit push -u origin master

购买服务器

能够在阿里云、腾讯云等购买云主机(我这购买的是 UCloud 的 ubuntu )。
记住服务器的 用户名明码外网IP

登录服务器并生成公私钥

进入github demo 目录,点击右上角的设置,抉择,secrets。
新建 名称: SSH_PRIVATE_KEY 值:服务器中设置的私钥值。

github 中创立 action

name: Test build and deploy siteon:  push:    branches:       - masterjobs:  CI_CD:    runs-on: ubuntu-latest    steps:      - uses: actions/checkout@v2      - uses: actions/setup-node@v2-beta        with:          node-version: 14      - run: npm ci      - run: npm run-script build      - uses: wlixcc/SFTP-Deploy-Action@v1.0        with:            username: '***'   #服务器的用户名          server: '****' #服务器的外网IP          ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} #援用之前创立好的secret          local_path: './build/*'  # 对应咱们我的项目build的文件夹门路          remote_path: '***' 咱们指定要把代码搁置在服务器的什么目录下