我有一个 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.
例如:
将以下代码添加到您的 package.json
文件中:
<代码>构建":{"extraResources": ["./extraResources/**"]}
这篇关于Electron - 如何添加外部文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!