首页 > 解决方案 > How should I configure Webpack for a react website to be able to use it without a server

问题描述

I'm building a react website. The goal for it is to be able to simply put the finished website on a USB key and be able to use it on a computer without any internet access.

I'm using react v16.6. I've already tried to simply open the build/index.html file but I received a few Not allowed to load local resource: file:///static/... and the page was blank. This projects is using a JSON file, pictures and videos.

I don't really know where I should go from here to be able to this.

Thanks for any help.

标签: reactjswebpack

解决方案


根据您的一些详细信息,我假设您正在使用 create-react-app。

如果您阅读错误消息或查看 build.html,您会看到构建的站点正在尝试从/build/static/js/.... 这将有效地尝试从文件系统的根目录加载文件,而不是当前目录。您可以"homepage": "."在 package.json 中进行设置,构建的站点将正确加载文件。这记录在您收到的消息中,该消息npm run build还链接到https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#deployment更多细节。


推荐阅读