簡體   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