electron-builderでパッケージングすると画像が表示されない問題
extraFilesやextraResourcesの仕組みを使って開発中とパッケージングしたのを分岐する必要がある プロジェクト直下に画像用のimgフォルダがある場合
package.jsonに以下の記述を追加
{ "name": "sample", "version": "1.0.0", "description": "", // 略 "build": { "extraFiles": [ { "from": "img", "to": "resources", "filter": [ "**/*" ] } ], // 略 } }
画像のパスを以下みたいな感じで分岐を入れる
const trayImagePath = app.isPackaged ? path.join(process.resourcesPath!, '/trayicon.png') : path.join(__dirname, '../img/trayicon.png');