[英]Electron Fetches Resources of React From Root Dir
I spent the last week trying some of recipes to glue Electron + React, but, each of them has its cons. 我花了最后一周的时间尝试一些配方来粘合Electron + React,但是每个配方都有其缺点。
Today, thought to do it by: 今天,考虑通过以下方式做到这一点:
create-react-app ...
npm install electron --save-dev
Put all Electron logic into build
dir of React (must do some work to keep theme there after the coming step 5, because it will clear build
dir) 将所有电子逻辑放入React的
build
目录中(必须做一些工作以在接下来的步骤5之后将主题保留在那里,因为它将清除build
目录)
Using Electron's window.loadURL('file://.../index.html')
(index.html) is react built HTML 使用Electron的
window.loadURL('file://.../index.html')
(index.html)来生成HTML
npm run build
(will build react app) npm run build
(将构建react应用)
npx electron ./build/main.js
Wow! 哇! it worked like charm.
它像魅力一样运作。 But, there is only one conflict I need to know how to fix, which is:
但是,我只需要知道一个冲突就可以解决,即:
React is writing links and sources as /../..
which Electron understands as root
directory of the system, and I have to add the dot
manually before each src
to be ./../..
, which fixed the conflict. React正在将链接和源代码写为
/../..
其理解为系统的root
目录,我必须在每个src
为./../..
之前手动添加dot
,以解决冲突。
But, that would be almost impossible to do by hand for all the links in app! 但是,对于应用程序中的所有链接,几乎不可能手动完成! So, please, how can this done automatically.
因此,请如何自动完成此操作。
Solved it today.. 今天解决了..
Just add property "homepage" : "./"
to package.json
, check this issue comment on create-react-app 只需将属性
"homepage" : "./"
到package.json
, 在create-react-app上检查此问题注释
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.