Introduction
electron-egg supports packaging your application for HarmonyOS (OpenHarmony). The Electron build artifacts are extracted and copied into a HarmonyOS HAP resource directory, where the HAP project's web engine loads them.
This is handled by the ohos command in ee-bin, which follows electron-builder's extraResources FileSet pattern (from / to / filter) for flexible resource selection.
Configuration
Declare the resources to extract under the ohos key in your bin.js config. Each entry is a FileSet:
javascript
// config/bin.js (or bin.json)
module.exports = {
// ...other ee-bin config
ohos: {
resources: [
{
from: 'out/extraResources',
to: 'ohos_hap/web_engine/resources',
filter: ['**/*', '!compiled'] // copy everything except the compiled dir
}
]
}
}| Field | Type | Description |
|---|---|---|
from | string | Source path (relative to project root) of the build artifacts to copy |
to | string | Destination path (relative to project root) inside the HAP resource directory |
filter | string[] | Glob patterns. **/* matches all; !pattern excludes. Defaults to ['**/*'] |
Usage
Run the ohos-resources npm script (defined in package.json):
bash
npm run ohos-resourcesWhich executes:
bash
ee-bin ohos --cmds=resources--cmds accepts a comma-separated list of keys under ohos to process. If omitted, all array-type properties under ohos are processed.
How it works
For each resource entry, ee-bin:
- Validates that the
fromsource path exists (skips with a warning if not). - Selects files matching the
filterpatterns via glob (supports negation like!compiled). - Copies each matched file to
to, preserving directory structure. - Uses an atomic copy strategy: the existing destination is renamed to a
.bakbackup before copying, and the backup is deleted only after the new copy succeeds. If the copy fails, the backup is restored — so a failed run never leaves a broken destination.
