Skip to content

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
      }
    ]
  }
}
FieldTypeDescription
fromstringSource path (relative to project root) of the build artifacts to copy
tostringDestination path (relative to project root) inside the HAP resource directory
filterstring[]Glob patterns. **/* matches all; !pattern excludes. Defaults to ['**/*']

Usage

Run the ohos-resources npm script (defined in package.json):

bash
npm run ohos-resources

Which 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:

  1. Validates that the from source path exists (skips with a warning if not).
  2. Selects files matching the filter patterns via glob (supports negation like !compiled).
  3. Copies each matched file to to, preserving directory structure.
  4. Uses an atomic copy strategy: the existing destination is renamed to a .bak backup 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.