mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
2.1 KiB
2.1 KiB
Applies to: Windows, MacOS, Linux
Getting Started: JS / Electron
This quick start is slightly tailored to Electron, so if you are using pure nodejs and bundling your app using pkg or similar you can ignore those steps.
- Add Velopack to your
package.json:
npm install velopack
- Add the following code to your entry point (eg.
index.js) as early as possible (before any electron startup code etc.):
const { VelopackApp } = require('velopack');
// Velopack builder needs to be the first thing to run in the main process.
// In some cases, it might quit/restart the process to perform tasks.
VelopackApp.build().run();
// ... your other app startup code here
- Add auto-updates somewhere to your app:
const { UpdateManager } = require('velopack');
async function updateApp()
{
const um = new UpdateManager();
um.setUrlOrPath("https://the.place/you-host/updates");
const updateInfo = await um.checkForUpdatesAsync();
if (!updateInfo) {
return; // no update available
}
await um.downloadUpdatesAsync(updateInfo.targetFullRelease, p => {
console.log(`progress: ${p}%`);
});
um.applyUpdatesAndRestart(updateInfo.targetFullRelease);
}
- If you are using electron/forge, you will need to add an asar unpack rule:
module.exports = {
packagerConfig: {
asar: {
// velopack contains native binaries which must remain unpacked
unpack: '**/node_modules/velopack/**',
},
},
}
- Compile your app to a binary (eg.
.exeon Windows). Example using electron forge:
npx electron-forge package
- Install the
vpkcommand line tool:
dotnet tool update -g vpk
Note: you must have the .NET Core SDK 6 installed to use and update the vpk
- Package your Velopack release / installers:
vpk pack -u MyAppUniqueId -v 1.0.0 -p /myBuildDir -e myexename.exe
✅ You're Done! Your app now has auto-updates and an installer.
You can upload your release to your website, or use the vpk upload command to publish it to the destination of your choice.