Bundling & Distribution
Continuing on from the Creating UI guide.
Let's add two more scripts to package.json to get our app ready for distribution: build:canary and build:stable.
{
"name": "my-app",
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"electrobun": "^0.0.1"
},
"scripts": {
"start": "bun run build:dev && electrobun dev",
"build:dev": "bun install && electrobun build",
"build:canary": "electrobun build --env=canary",
"build:stable": "electrobun build --env=stable"
}
} In your terminal you can now run:
bun run build:canary
# or
bun run build:stable Both of these non-dev builds will:
- Build an optimized app bundle
- Tar and compress it using state-of-the-art ZSTD compression
- Generate a self-extracting app bundle
- Create an
artifactsfolder for distribution
All you need to distribute your app is a static file host like S3 or Google Cloud Storage. There's no need to run a server beyond that.
Assuming you've set up a Google Cloud Storage bucket with a subfolder for this application, add it to electrobun.config.ts:
export default {
app: {
name: "My App",
identifier: "dev.my.app",
version: "0.0.1",
},
build: {
bun: {
entrypoint: "src/bun/index.ts",
},
views: {
"main-ui": {
entrypoint: "src/main-ui/index.ts",
},
},
copy: {
"src/main-ui/index.html": "views/main-ui/index.html",
},
},
release: {
bucketUrl: "https://storage.googleapis.com/mybucketname/myapp/",
},
}; You can make your app available by uploading the contents of the artifacts folder into the myapp folder of your bucket.
The artifacts folder will create a subfolder for each channel-build-target combination (for example canary-macos-arm64). By default the Electrobun CLI builds for the current machine's target and automatically downloads the core/CEF files during bundling.
To cross-bundle for multiple targets, update your scripts with the --targets option:
"build:canary": "electrobun build --env=canary --targets=macos-x64" "build:canary": "electrobun build --env=canary --targets=all" Once you've uploaded artifacts to your bucket, the next time you run a non-dev build (like bun run build:canary) the Electrobun CLI will download the current version of your app using release.bucketUrl and generate a patch file using our optimized BSDIFF implementation. That patch file gets added to your artifacts folder.
It's recommended to keep older patch files in your storage. Users on older versions can download successive patches, each as small as 14KB. If patching can't get the user to the latest version, Electrobun's Updater falls back to downloading the full latest build.
Visit the Updater API docs to learn how to make your app check for and install updates.
Artifacts Folder Contents
Assuming your app's name is MyApp and you did a canary build on an ARM Mac, you'll see:
// This file contains metadata for the version you just built
/artifacts/canary-macos-arm64/update.json
// Link this dmg on your marketing site for first-time installs
/artifacts/canary-macos-arm64/MyApp-canary.dmg
// Compressed tar of your app bundle (also embedded in the dmg)
/artifacts/canary-macos-arm64/MyApp-canary.app.tar.zst
// Patch files are named <hash>.patch and represent diffs from prior versions
/artifacts/canary-macos-arm64/jsf87yasf.patch When replacing the contents of your static file host, keep as many old patch files as you like so older app versions can step through them to reach the latest build.