CLI Commands
The Electrobun CLI provides commands for initializing new projects and building your applications for different environments.
Installation
When you install Electrobun, the CLI tool is added to your node_modules/bin folder:
bun install electrobunThis makes the electrobun command available in your npm scripts or via bunx/npx.
Commands
electrobun init
Initializes a new Electrobun project with starter templates.
Usage
# Interactive template selectionelectrobun init
# Direct template selectionelectrobun init [template-name]Available Templates
hello-world- Basic single-window applicationphoto-booth- Camera app with photo capture functionalityinteractive-playground- An interactive playground of Electrobun apismultitab-browser- Multi-tabbed web browser
Examples
# Choose template interactivelybunx electrobun init
# Initialize with photo-booth template directlybunx electrobun init photo-booth
# Initialize with multitab-browser templatebunx electrobun init multitab-browserelectrobun build
Builds your Electrobun application according to the configuration in electrobun.config.ts.
Usage
electrobun build [options]Options
| Option | Description | Values | Default |
|---|---|---|---|
—env | Build environment | dev, canary, stable | dev |
Builds always target the current host platform and architecture. To build for multiple platforms, use CI runners for each OS/architecture (see Cross-Platform Development).
Examples
# Development build for current platformelectrobun build
# Development build with environment flagelectrobun build --env=dev
# Canary buildelectrobun build --env=canary
# Stable (production) buildelectrobun build --env=stableelectrobun run
Launches an already-built dev bundle. This is useful when you’ve already run electrobun build and just want to relaunch the app without rebuilding.
Usage
electrobun runelectrobun dev
Builds your application in dev mode and then launches it. This is the primary command for day-to-day development — equivalent to running electrobun build --env=dev followed by electrobun run.
Usage
electrobun dev [options]Options
| Option | Description |
|---|---|
—watch | Watch source files for changes and automatically rebuild + relaunch |
Examples
# Build and launch in dev modeelectrobun dev
# Build, launch, and watch for changeselectrobun dev --watchWatch Mode
When using --watch, Electrobun automatically watches your source directories for file changes:
- The directory containing your
build.bun.entrypoint - Directories containing each view entrypoint
- Source paths from
build.copy - Any additional paths specified in
build.watch
When a file change is detected, the running app is killed, a fresh build runs (including all lifecycle hooks like postBuild), and the app is relaunched. File watchers are paused during builds to avoid false triggers from build output.
Changes are debounced (300ms) so rapid saves only trigger a single rebuild. If a build fails, the error is logged and the watcher keeps running — the app will rebuild on the next file change.
Use build.watchIgnore in your config to exclude files from triggering rebuilds (e.g., generated assets). See Build Configuration for details.
Press Ctrl+C to stop the app and exit watch mode.
Build Environments
Development (dev)
- Outputs logs and errors to terminal
- No code signing or notarization
- Creates build in
build/folder - No artifacts generated
- Fast iteration for testing
Canary
- Pre-release/beta builds
- Optional code signing and notarization
- Generates distribution artifacts
- Creates update manifests for auto-updates
- Suitable for testing with limited users
Stable
- Production-ready builds
- Full code signing and notarization (if configured)
- Optimized and compressed artifacts
- Ready for distribution to end users
- Generates all update files
Build Script Examples
Basic Setup
{ "scripts": { "start": "electrobun run", "dev": "electrobun dev", "dev:watch": "electrobun dev --watch", "build:canary": "electrobun build --env=canary", "build:stable": "electrobun build --env=stable" }}CI Build Scripts
For multi-platform distribution, run the same build command on each platform’s CI runner:
{ "scripts": { "build:dev": "electrobun build", "build:canary": "electrobun build --env=canary", "build:stable": "electrobun build --env=stable" }}