我是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"
}
}
最佳答案
您需要添加
"homepage": "http://mywebsite.com/relativepath",
在你的 package.json 文件中(如果它托管在服务器上的某个地方)。 或者要在本地运行它,您需要输入以下命令
npm install -g serve
serve -s build
或者你在使用react-router时可以设置
编辑
"homepage": "."
在本地工作
了解更多信息read here
关于node.js - 构建Reactjs空白页面并且不生成其他页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59928729/