reactjs - 如何在 gh-pages(github 页面)上部署我的 React 应用程序?
问题描述
我正在尝试使用 gh-pages 部署我的 react 应用程序,上传后我发现了白页。我尝试了很多解决方案,但没有任何效果。
这是网址:
https://mosherad.github.io/spreago-react/
这是json文件
{
"name": "spreago",
"version": "0.1.0",
"private": true,
"dependencies": {
"@apollo/react-hooks": "^3.1.3",
"@hapi/hawk": "^7.1.2",
"@material-ui/core": "^4.8.0",
"@material-ui/icons": "^4.5.1",
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.4.0",
"@testing-library/user-event": "^7.2.1",
"apollo-boost": "^0.4.7",
"bootstrap": "^4.4.1",
"gh-pages": "^2.2.0",
"graphql": "^14.5.8",
"history": "^4.10.1",
"lodash.flowright": "^3.5.0",
"react": "^16.12.0",
"react-apollo": "^3.1.3",
"react-bootstrap": "^1.0.0-beta.16",
"react-dom": "^16.12.0",
"react-icons": "^3.8.0",
"react-material-ui-form-validator": "^2.0.9",
"react-router-dom": "^5.1.2",
"react-scripts": "3.3.0",
"serve": "^11.3.0",
"yarn": "^1.21.1",
"yarn-install": "^1.0.0"
},
"homepage": "https://mosherad.github.io/spreago-react/",
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"predeploy": "npm run build",
"deploy": "gh-pages -d 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"
]
},
"devDependencies": {
"eslint": "^6.7.2"
}
}
解决方案
首先,您将检查您的回购名称。
然后在主页后添加以下行到 packet.json
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
并安装了 gh-pages:
npm install --save gh-pages
我将所有内容推送到 github 并使用以下命令进行部署:
npm run deploy