[英]How to run React application by clicking index.html file without any local server
I have created react application using create-react-app when I start "npm start" it is running using localhost:3000 in browser which is fine.当我启动“npm start”时,我使用 create-react-app 创建了反应应用程序,它在浏览器中使用 localhost:3000 运行,这很好。 But, when I click index.html from project folder it is showing blank page.
但是,当我从项目文件夹中单击 index.html 时,它显示空白页。 Can you suggest me solutions on how to run react application using index.html file
你能给我建议如何使用 index.html 文件运行反应应用程序的解决方案吗
Add "homepage": ".",
to the top of your package.json
file.将
"homepage": ".",
添加到package.json
文件的顶部。 Then build with yarn build
or npm build
.然后用
yarn build
或npm build
。 Go to build/
folder and double click on index.html
. Go
build/
文件夹并双击index.html
。
EDIT:编辑:
Opening the app via index.html needs
"homepage": "."
通过index.html打开应用需要
"homepage": "."
inpackage.json
because without it Webpack tries to load the static files from the root the file system rather than build directory.in
package.json
because without it Webpack tries to load the static files from the root the file system rather than build directory. Reference参考
You can run npm run build
, then go to the “build” folder where a working index.html will be located.您可以运行
npm run build
,然后运行 go 到“build”文件夹,工作 index.html 将位于该文件夹。 The index.html in the project folder isn't built for production/standalone use.项目文件夹中的 index.html 不是为生产/独立使用而构建的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.