問題描述
我有一個 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 - 如何添加外部文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!