TIP
当前处于实验阶段,请持续关注更新。
介绍
electron-egg 支持将应用打包为鸿蒙(OpenHarmony)版本。Electron 构建产物会被提取并拷贝到 HarmonyOS HAP 的资源目录中,由 HAP 工程的 web 引擎加载。
该能力由 ee-bin 的 ohos 命令实现,遵循 electron-builder 的 extraResources FileSet 规范(from / to / filter),可灵活选择资源。
配置
在 bin.js 配置的 ohos 字段下声明要提取的资源,每个条目为一个 FileSet:
javascript
// config/bin.js(或 bin.json)
module.exports = {
// ...其它 ee-bin 配置
ohos: {
resources: [
{
from: 'out/extraResources',
to: 'ohos_hap/web_engine/resources',
filter: ['**/*', '!compiled'] // 拷贝所有文件,排除 compiled 目录
}
]
}
}| 字段 | 类型 | 说明 |
|---|---|---|
from | string | 源路径(相对项目根目录),即要拷贝的构建产物 |
to | string | 目标路径(相对项目根目录),位于 HAP 资源目录内 |
filter | string[] | glob 匹配规则。**/* 匹配所有;!pattern 表示排除。默认 ['**/*'] |
使用
运行 package.json 中定义的 ohos-resources 脚本:
bash
npm run ohos-resources其等价于:
bash
ee-bin ohos --cmds=resources--cmds 接受逗号分隔的 ohos 下的 key 列表。若省略,则处理 ohos 下所有数组类型的配置项。
