0

我是 reactjs 的新手,刚刚创建了我的第一个 reactjs 应用程序,我想制作生产版本,并使用了这个命令:

npm run build

但是在生成的只是一个空白的 index.html 文件,为什么?因为我有很多路线,如何访问其他页面?为什么索引是空白的?

{
  "name": "test",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.19.0",
    "express": "latest",
    "nodemon": "^2.0.1",
    "react": "^16.9.0",
    "react-dom": "^16.9.0",
    "react-router-dom": "^5.0.1",
    "react-scripts": "3.1.0",
    "semantic-ui-css": "^2.4.1",
    "semantic-ui-react": "^0.88.1",
    "socket.io": "^2.3.0"
  },
  "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"
    ]
  },
  "devDependencies": {
    "universal-cookie": "^4.0.2"
  }
}
4

2 回答 2

2

你需要添加

"homepage": "http://mywebsite.com/relativepath",

在你的 package.json 文件中,如果它在服务器上托管的话。或者要在本地运行它,您需要输入以下命令

npm install -g serve
serve -s build

或者您在使用 react-router 时可以设置

编辑

"homepage": "."

在本地工作

有关更多信息,请阅读此处

于 2020-01-27T10:05:52.027 回答
0

尝试

npm run build -- --profile
于 2020-01-27T10:07:27.443 回答