简体   繁体   English

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

[英]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 buildnpm 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": "." in package.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.

相关问题 当 webpack 服务器运行时,如何运行不同的 html 文件而不是 index.html? - how to run a different html file instead of index.html when webpack server runs? 我如何在没有Index.html或.php的情况下将WebApplication文件运行到服务器? - How can I run my WebApplication files to the server without an Index.html or.php? 如果没有 index.html,如何在 index.html 中运行脚本 - How to run scripts in index.html in react if you don't have index.html 如何在React中从index.html引用CSS文件 - How to refer a css file from index.html in React 如何在 react js 中的 index.html 文件中添加条件 - How to add condition in index.html file in react js 我可以在没有 npm 启动和 npx create-react-app 的情况下使用 React 运行 index.html 吗? - Can I run index.html with React without npm start and npx create-react-app? 重定向到 index.html 文件中的反应 onclick - Redirect to index.html file in react onclick 我的node.js react应用程序无法识别任何index.html文件有明显的原因吗? - Are there any obvious reasons my node.js react app is not recognizing any index.html file? HTML5在index.html中导入外部本地html文件 - HTML5 Importing external local html file in index.html 为什么 styles 没有包含在本地服务器上的 index.html 中 - Why are styles not being included in index.html on the local server
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM