Electron - How to add external files?(Electron - 如何添加外部文件?)
问题描述
我有一个 Electron 应用程序.我尝试让应用程序打开一个 .exe 文件.我在名为 lib 的根文件夹中创建了一个目录,并将 .exe 文件放在那里.在开发中,我使用
__dirname + '/lib/file.exe
打开文件没有问题,但是当我打包应用程序时(使用 yarn dist
),它确实不打开exe文件,dist
文件夹下也没有lib
文件夹了.
I have an Electron app. I try to make the app open an .exe file. I created a directory in the root folder named lib
and placed the .exe file there. In development, I have no problem opening the file by using __dirname + '/lib/file.exe
, but when I package the app (using yarn dist
), it does not open the exe file and there is no lib
folder anymore on the dist
folder.
我尝试使用 console.log(__dirname)
写入控制台默认位置,它输出 distwin-unpacked
esourcesapp.asa
(即一个文件).
I tried writing to console the default location using console.log(__dirname)
and it outputs distwin-unpacked
esourcesapp.asa
(which is a file).
如何添加应用打包时可以访问的外部文件?
How can I add an external file that can be accessed when the app is packaged?
推荐答案
设法通过使用 extraResources 来解决它.应该在 package.json
文件中的 build 下声明.
Managed to solve it by using extraResources. Should be declared under build in your package.json
file.
例如:
- 在 pacakge.json 旁边创建一个名为 extraResources 的新文件夹
将以下代码添加到您的
package.json
文件中:
<代码>构建":{"extraResources": ["./extraResources/**"]}
这篇关于Electron - 如何添加外部文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Electron - 如何添加外部文件?


- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01