reactjs - 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.
解决方案
根据您的一些详细信息,我假设您正在使用 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更多细节。
推荐阅读
- javascript - VueJS (w/Vuetify) 可能需要额外的加载器用于作用域 css
- r - 如何在ggplot2中删除日期轴上的间隙
- apache - Gitlab 中的嵌入式 Grafana 无法通过反向代理工作
- vb.net - 如何创建动态 Linq 表达式树 VB.net
- forms - 构建函数在 Flutter 表单验证中返回 null
- r - 将指示符矩阵对应于 R 中的列名
- angular - 在 Angular 8 中,如何将一个组件传递给另一个组件的输入,然后在路由器模块中强制使用它
- firebase - Firebase CLI 更改托管目标
- python - Python正则表达式,如何找到两个浮点数之间的数字
- reactjs - 在本机反应中启用调试器时,没有组件工作(TextInput)