当我使用$calculated_disp_order = $order['disp_order']+1;
在本地运行React.js前端时,它运行良好。当我尝试先在npm start
然后在npm install
的服务器中运行它时,将显示空白页面。
我检查了nom start
文件夹,它在public
中具有以下内容:
index.html
在<head>
<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css"
integrity="sha384-akgkshgfs"
crossorigin="anonymous">
</head>
<div id="root"></div>
中,我使用package.json
:
http-server -a XXX.XXX.XXX.XXX -p 55000
在本地时,我使用:
"scripts": {
"start": "http-server -a XXX.XXX.XXX.XXX -p 55000",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
它在"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
}
中工作良好,但是在服务器中,localhost:3000
中的页面为空白。
看来我错过了一些安装步骤。
有什么想法吗? (这是我第一次使用React.js和Node。)。
答案 0 :(得分:1)
http-server
使用./public
作为网站的默认入口点(如果未指定任何内容(docs)。
如评论中所述,您在服务器上构建项目,因此捆绑的项目位于/build
内部。因此,http服务器没有要显示的内容。
要显示该站点,您必须从以下位置更改启动脚本
"start": "http-server -a XXX.XXX.XXX.XXX -p 55000",
到
"start": "http-server /build -a XXX.XXX.XXX.XXX -p 55000",
-
如评论中所述,最好在本地构建生产站点,而仅部署捆绑的代码。 请参阅以下文章,以获取有关更好的部署的更多信息: