从 ES6 导入的文件创建一个 Electron nativeImage?

问题描述

我们正在努力改进我们的构建系统,以减少对相对路径导入的依赖,我们需要为此努力的一个领域是图像加载。所以我们正在尝试做这样的事情,用 Electron 的 nativeImage 加载图像:

import { nativeImage } from 'electron';
import ourImage from 'our-images/src/ourImage.png' 

console.log(ourImage) // Outputs 14ad9a9efa18beb2868a.png

const trayIcon = nativeImage.createFromPath(ourImage); // Blank icon appears - no error message
const trayIcon = nativeImage.createFromBuffer(ourImage); // App crashes: "Error: buffer must be a node Buffer" - even if we load the file using `type: asset/source` -- https://webpack.js.org/guides/asset-modules/

有什么方法可以在 Electron 和 Webpack 中使用这种模式?还是我们被迫使用 require() 和相对路径?我们最初尝试使用 require.resolve() 使用路径而不是创建 nativeImage,但不幸的是,它在打包的应用程序中无法始终如一地工作。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)