I am developing an electron application where I am using external .exe files. In development mode application works fine. But when I package the application, it is unable to find those .exe files.
How to include .exe files in packaged application. I am using electron-builder for packaging.
Below is my configuration,
"build": {
"appId": "com.f.quickstart",
"files": [
"app/build/**/*",
"app/build/**/*.exe",
"main.js",
"mainIPC.js",
"src/**/*",
"dist/**/*",
"node_modules/**/*",
"package.json"
],
"win": {
"target": "portable",
"signAndEditExecutable": false
},
"linux": {
"target": "AppImage"
},
"mac": {
"target": "zip"
}
}
Note that I'm using: electron ^12.0.0, electron-builder ^23.6.0, and Windows 11.
If you only need the exe in your installer, you can just use a resources directory. This is useful, for example, when you want to run an exe that installs dependencies during your app's installation.
Here's an example using an nsis installer:
resources directory in your root directory.build rule:// package.json
{
...
"build": {
"appId": "mycompany.MyProductName",
"productName": "MyProductName",
"directories": {
"buildResources": "resources"
},
"nsis": {
"oneClick": false,
"perMachine": true
},
"win": {
"target": "nsis"
},
"extends": null
}
}
Create a vendor directory within your new resources directory.
Drag your exe into the vendor directory.
Create a file called installer.nsh within the resources directory, and write something like:
!define vendordir "${BUILD_RESOURCES_DIR}\vendor"
!define myexe_64 "myexe.exe"
!define myexe "myexe_x86.exe"
!macro customInstall
${If} ${RunningX64}
ExecWait '"${vendordir}\${myexe_64}"'
${Else}
ExecWait '"${vendordir}\${myexe}"'
${EndIf}
!macroend
dist command for Windows.Using an exe during runtime is such a common use case that I'm honestly surprised how little documentation I could find for this.
Here's an example of how I do it:
Create a directory called extras anywhere in your project. I put mine at src/main/extras.
Add an entry for extraFiles in your build rule:
// package.json
{
...
"build": {
"extraFiles": [
{
"from": "src/main/extras",
"to": "extras",
"filter": [
"**/*"
]
}
],
}
}
// preload.js
const { remote } = require('electron');
const path = require('path');
const isDev = require('electron-is-dev');
const appPath = remote.app.getAppPath();
const extrasPath = isDev ?
path.join(appPath, 'src', 'main', 'extras') :
path.join(appPath, '..', '..', 'extras');
// We finally have our exe!
const exePath = path.join(extrasPath, 'myexe.exe');
The Electron Builder configuration docs are still a good resource for details.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With