介绍
electron-egg 支持将应用打包为鸿蒙(HarmonyOS)版本。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/mac-arm64/ee.app/Contents/Resources/app',
to: './ohos_hap/web_engine/src/main/resources/resfile/resources/app',
filter: [
"**/*",
"!README.md",
"!README.zh-CN.md"
]
},
{
from: './out/mac-arm64/ee.app/Contents/Resources/extraResources',
to: './ohos_hap/web_engine/src/main/resources/resfile/resources/extraResources',
filter: [
"**/*"
]
}
]
}
}| 字段 | 类型 | 说明 |
|---|---|---|
from | string | 源路径(相对项目根目录),即要拷贝的构建产物 |
to | string | 目标路径(相对项目根目录),位于 HAP 资源目录内 |
filter | string[] | glob 匹配规则。**/* 匹配所有;!pattern 表示排除。默认 ['**/*'] |
使用
运行 package.json 中定义的 ohos 脚本:
bash
npm run ohos
# 自定义测试命令
npm run ohos-test其等价于:
bash
ee-bin ohos --cmds=resources
# 自定义测试命令
ee-bin ohos --cmds=resources_public--cmds 接受逗号分隔的 ohos 下的 key 列表。若省略,则处理 ohos 下所有数组类型的配置项。
