电子-如何添加外部文件? [英] Electron - How to add external files?

查看:80
本文介绍了电子-如何添加外部文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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)编写控制台默认位置的命令,并输出\dist\win-unpacked\resources\app.asa(这是一个文件).

I tried writing to console the default location using console.log(__dirname) and it outputs \dist\win-unpacked\resources\app.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.

例如:

  1. 在pacakge.json旁边创建一个名为extraResources的新文件夹
  2. 将以下代码添加到您的package.json文件中:

"build": { "extraResources": ["./extraResources/**"] }

"build": { "extraResources": ["./extraResources/**"] }

这篇关于电子-如何添加外部文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆