Using electron-packager I can create a 'packaged' version of my JavaScript application for various architectures and platforms. However, it does not package each build as a single binary which I can distribute.
When looking for alternatives I found out about EncloseJs, but it is not free (and I prefer a free solution).
Another one I found was electron-boilerplate, which only creates a *.deb, *.app or a Windows installer, but not a single executable which will run the program.
Is it possible to use Electron to create a single executable file?
This make command contains two steps: It will first run electron-forge package under the hood, which bundles your app code together with the Electron binary. The packaged code is generated into a folder. It will then use this packaged app folder to create a separate distributable for each configured maker.
Try using electron-builder -p --win
. it will build up the production-ready .exe
. I did it with [email protected]
for the publishable build, you'll need the publishing provider in your package.json
file, consider the given example.
"build": { "appId": "com.trinityinfosystem.electron.exchange.stream", "productName": "Accurate", "copyright": "Copyright © 2018 Trinity InfoSystem", "mac": { "category": "public.app-category.utilities", "icon": "assets/icon.icns", "target": [ "zip", "dmg" ], "publish": [ "github" ] }, "win": { "publisherName": "Trinity InfoSystem", "publish": [ "github" ], "target": [ "nsis" ] }, "linux": { "target": [ "AppImage", "tar.gz" ] }, "dmg": { "background": "assets/background.png", "icon": "assets/icon.icns", "title": "Accurate Installer" }, "nsis": { "oneClick": false, "perMachine": false, "allowToChangeInstallationDirectory": true, "installerIcon": "assets/icon.ico", "installerSidebar": "assets/sidebar.bmp", "uninstallerSidebar": "assets/sidebar.bmp", "license": "assets/agreement.html", "createDesktopShortcut": true, "createStartMenuShortcut": true }, "publish": [ { "provider": "github", "owner": "vkiranmaniya", "repo": "accurate", "vPrefixedTagName": true, "private": true, "releaseType": "draft" } ] },
Add the given pulishing config to your package.json as root proprty. You will need the Github personal access token (here is the Doc) to be exported while running a build.
You can export the token as env
variable from main.js
as given,
process.env.GH_TOKEN = 'YOUR_PERSONAL_ACCESS_TOKEN_HERE';
If you want to setup AutoUpdate using GitHub, you can use the given module and call checkForUpdates()
method from main.js
const electron = require("electron"); const updater = require("electron-updater"); const autoUpdater = updater.autoUpdater; autoUpdater.on('checking-for-update', function () { sendStatusToWindow('Checking for update...'); }); autoUpdater.on('update-available', function (info) { sendStatusToWindow('Update available.'); }); autoUpdater.on('update-not-available', function (info) { sendStatusToWindow('Update not available.'); }); autoUpdater.on('error', function (err) { sendStatusToWindow('Error in auto-updater.'); }); autoUpdater.on('download-progress', function (progressObj) { let log_message = "Download speed: " + progressObj.bytesPerSecond; log_message = log_message + ' - Downloaded ' + parseInt(progressObj.percent) + '%'; log_message = log_message + ' (' + progressObj.transferred + "/" + progressObj.total + ')'; sendStatusToWindow(log_message); }); autoUpdater.on('update-downloaded', function (info) { sendStatusToWindow('Update downloaded; will install in 1 seconds'); }); autoUpdater.on('update-downloaded', function (info) { setTimeout(function () { autoUpdater.quitAndInstall(); }, 1000); }); function checkForUpdates(){ const data = { 'provider': 'github', 'owner': 'vkiranmaniya', 'repo': 'exchange', 'token': 'YOUR_PERSONAL_TOKEN_HERE' }; autoUpdater.setFeedURL(data); autoUpdater.checkForUpdates(); } function sendStatusToWindow(message) { console.log(message); } module.exports = { checkForUpdates, }
Now you can run the command electron-build -p --win
to build an auto updatable standalone .exe file. Use --mac
or --linux
to target specific platform for build.
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