简体   繁体   中英

Build Reactjs blank page and not generated other pages

I am newbie in reactjs, just create my first reactjs app, I want to make production version, and used this command:

npm run build

But in generated just a blank index.html file, why? Because I have many routes , how can I access other pages? and why index is blank?

{
  "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"
  }
}

you need to add

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

in your package.json file if its hosted somewhre on server. or to run it locally you need to type following command

npm install -g serve
serve -s build

or you when using react-router you can set

EDIT

"homepage": "."

to work it locally

for more info read here

尝试

npm run build -- --profile

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM