[英]How can I deploy react app on github pages?
我嘗試將我的 React Web 應用程序部署到 github 頁面,但是當我找不到在線網站時,在控制台中,它說該應用程序已准備好發布,我應該運行命令npm run deploy
但每次我看到相同的消息時運行該命令 這是package.json
文件:
{
"name": "weather-app",
"version": "0.1.0",
"private": true,
"homepage": "http://shotiko-forecast.github.io/weather",
"dependencies": {
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-redux": "^7.1.3",
"react-scripts": "1.1.4",
"redux": "^4.0.4",
"redux-thunk": "^2.3.0"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject",
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
> npm i gh-pages
"homepage": "https://username.github.io/repo-name",
"scripts": {
"deploy": "gh-pages -d build"
}
npm run build
npm run deploy
https://username.github.io/repo-name
你的 React 應用程序的名稱是 weather-app。 我假設該應用程序的 github 存儲庫被命名為 weather-app。 您的 package.json 文件中存在錯誤。 主頁屬性設置不正確。 它應該設置為,
"homepage": "http://<<github-user-name>>.github.io/<<github-repo-name>>"
在您的情況下,將天氣更改為天氣應用程序,一切正常
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.