如何在github页面上部署React应用?

时间:2019-11-27 18:45:33

标签: reactjs deployment 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"
    ]
  }
}

command prompt github pages

2 个答案:

答案 0 :(得分:0)

  1. 为项目安装依赖项。
True
  1. 在您的package.json中添加脚本和主页
print (sum(x.startswith('aa') for x in df['something'].unique()))
3
  1. 运行构建脚本以进行生产
> npm i gh-pages
  1. 运行部署脚本以将代码部署到它自动在git-hub gh-pages分支上推送的页面上,并在gh-pages分支上自动选择,您可以检查设置> GitHub页面。
"homepage": "https://username.github.io/repo-name",
"scripts": {
    "deploy": "gh-pages -d build"
}
  1. 现在该检查您的
npm run build

答案 1 :(得分:0)

你的 React 应用的名称是 weather-app。我假设该应用程序的 github 存储库被命名为 weather-app。您的 package.json 文件中存在错误。主页属性设置不正确。 它应该设置为,

"homepage": "http://<<github-user-name>>.github.io/<<github-repo-name>>"

在您的情况下,将天气更改为天气应用程序,一切正常