簡體   English   中英

如何在 GitHub Pages 上部署帶有節點后端的 React 應用程序?

[英]How can I deploy a react app with a node backend on GitHub Pages?

我剛剛開始學習並發 npm 到 React。
我想知道如何在 Github 頁面上同時使用 npm 部署 React 項目。
通常在本地機器上,我們會使用服務器端 package.json 文件運行應用程序

"dev": "同時"npm run server" "npm run client""
在終端> npm run dev

我嘗試使用 gh-pages npm 在 Github 頁面上部署 react 應用程序,但同時使用 npm,
我不知道怎么做,因為有兩個 package.json。
另外,我對NODE環境和npm run build不太了解。

服務器端package.json:

{
 "name": "contact-keeper",
  "version": "1.0.0",
  "description": "Contact manager app",
  "main": "server.js",
  "homepage": "https://myprofile.github.io/Contact-Keeper-with-React",
"scripts": {
    "predeploy": "npm run build",
    "deploy": "gh-pages -d build",
    "start": "node server.js",
    "server": "nodemon server.js",
    "client": "npm start --prefix client",
    "clientinstall": "npm install --prefix client",
    "dev": "concurrently \"npm run server\" \"npm run client\""
  },
 "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "config": "^3.1.0",
    "dotenv": "^8.0.0",
    "express": "^4.17.1",
    "express-validator": "^6.1.1",
    "jsonwebtoken": "^8.5.1",
    "mongoose": "^5.6.4"
  },
  "devDependencies": {
    "concurrently": "^4.1.1",
    "gh-pages": "^2.1.1",
    "nodemon": "^1.19.1"
  }
}

客戶端服務器 package.json:

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.19.0",
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.0.1",
    "react-transition-group": "^4.2.1",
    "uuid": "^3.3.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
 "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
    "proxy": "http://localhost:5000"
}

是否有任何關於設置環境的文檔或基礎知識,我需要學習更多才能理解這個主題?

Github 不是(完全)為其他用戶提供您的工作應用程序的服務。 Github 是一個用於存儲代碼、更新代碼和管理版本的存儲庫。

我認為將您的應用程序“同時”部署到 github 意味着有一種方法可以使用新版本代碼更新 Github,同時將其在線部署到服務,例如 Heroku。

您應該研究並了解 Git(與 github 相對)是什么,因為它對開發至關重要。 在嘗試部署到 Heroku、AWS 等服務之前,首先要熟練使用 git 管理您的應用程序代碼......

編輯

正如 Asaf Aviv 所指出的,您可以使用 Github 頁面提供來自 Github 的前端應用程序,但您仍然需要能夠將本地代碼推送到 github 才能使其工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM