繁体   English   中英

如何在没有任何本地服务器的情况下通过单击 index.html 文件来运行 React 应用程序

[英]How to run React application by clicking index.html file without any local server

当我启动“npm start”时,我使用 create-react-app 创建了反应应用程序,它在浏览器中使用 localhost:3000 运行,这很好。 但是,当我从项目文件夹中单击 index.html 时,它显示空白页。 你能给我建议如何使用 index.html 文件运行反应应用程序的解决方案吗

"homepage": ".",添加到package.json文件的顶部。 然后用yarn buildnpm build Go build/文件夹并双击index.html 在此处输入图像描述 在此处输入图像描述

编辑:

通过index.html打开应用需要"homepage": "." in package.json because without it Webpack tries to load the static files from the root the file system rather than build directory. 参考

您可以运行npm run build ,然后运行 go 到“build”文件夹,工作 index.html 将位于该文件夹。 项目文件夹中的 index.html 不是为生产/独立使用而构建的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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