简介
ee-bin 配置的完整类型定义。./cmd/bin.js 文件遵循 BinConfig 接口结构,ee-bin 会将其与 bin_default.ts 的默认值深度合并,生成最终配置。
BinConfig
顶层配置接口 — ./cmd/bin.js 的完整结构。
typescript
interface BinConfig {
dev: DevConfig;
build: BuildConfig;
move: Record<string, MoveConfig>;
start: ExecConfig;
encrypt: Record<string, EncryptConfig>;
exec: Record<string, ExecConfig>;
updater?: Record<string, UpdaterConfig>;
ohos?: OhosConfig;
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
dev | DevConfig | 是 | 开发模式子进程配置(前端 + Electron) |
build | BuildConfig | 是 | 构建配置(Electron 打包 + 平台打包) |
move | Record<string, MoveConfig> | 是 | 资源移动配置(如前端 dist → public/dist) |
start | ExecConfig | 是 | 生产启动配置 |
encrypt | Record<string, EncryptConfig> | 是 | 加密配置(前端 + Electron,各自独立) |
exec | Record<string, ExecConfig> | 是 | 自定义命令配置(默认为空,用户自定义) |
updater | Record<string, UpdaterConfig> | 否 | 增量更新配置(按平台) |
ohos | OhosConfig | 否 | 鸿蒙资源提取配置 |
ExecConfig
命令执行配置 — 定义启动子进程的参数。
typescript
interface ExecConfig {
directory: string;
cmd: string;
args?: string[];
stdio?: 'inherit' | 'pipe' | 'ignore';
sync?: boolean;
protocol?: string;
watch?: boolean;
delay?: number;
hostname?: string;
port?: number;
indexPath?: string;
force?: boolean;
loadingPage?: string;
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
directory | string | 是 | 进程工作目录(相对于项目根目录) |
cmd | string | 是 | 要执行的命令(如 npm、electron、electron-builder) |
args | string[] | 否 | 命令参数数组 |
stdio | 'inherit' | 'pipe' | 'ignore' | 否 | 子进程 stdio 模式。默认:'inherit' |
sync | boolean | 否 | 同步执行。默认:false |
protocol | string | 否 | 前端协议。'http://' = 开发服务器,'file://' = 跳过前端 |
watch | boolean | 否 | 监听文件变更并自动重启(仅 Electron)。默认:false |
delay | number | 否 | 监听模式的防抖延迟(毫秒)。默认:1000 |
hostname | string | 否 | 前端开发服务器主机名 |
port | number | 否 | 前端开发服务器端口 |
indexPath | string | 否 | 前端首页文件名 |
force | boolean | 否 | 强制刷新页面。默认:false |
loadingPage | string | 否 | Electron 加载页路径(在主内容之前显示加载页) |
DevConfig
开发模式配置 — 前端和 Electron 子进程配置。
typescript
interface DevConfig {
frontend: DevFrontendConfig;
electron: DevElectronConfig;
[key: string]: ExecConfig | undefined;
}DevFrontendConfig
继承 ExecConfig,为前端开发服务器预设必填默认值。
typescript
interface DevFrontendConfig extends ExecConfig {
args: string[];
protocol: string;
hostname: string;
port: number;
indexPath: string;
force: boolean;
sync: boolean;
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
directory | string | 是 | 前端目录。默认:'./frontend' |
cmd | string | 是 | 命令。默认:'npm' |
args | string[] | 是 | 参数。默认:['run', 'dev'] |
protocol | string | 是 | 协议。默认:'http://' |
hostname | string | 是 | 主机名。默认:'localhost' |
port | number | 是 | 端口。默认:8080 |
indexPath | string | 是 | 首页。默认:'index.html' |
force | boolean | 是 | 强制刷新。默认:false |
sync | boolean | 是 | 同步模式。默认:false |
DevElectronConfig
继承 ExecConfig,为 Electron 进程预设必填默认值。
typescript
interface DevElectronConfig extends ExecConfig {
args: string[];
loadingPage: string;
watch: boolean;
sync: boolean;
delay: number;
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
directory | string | 是 | 目录。默认:'./' |
cmd | string | 是 | 命令。默认:'electron' |
args | string[] | 是 | 参数。默认:['.', '--env=local'] |
loadingPage | string | 是 | 加载页路径。默认:''/public/html/loading.html' |
watch | boolean | 是 | 监听模式。默认:false |
sync | boolean | 是 | 同步模式。默认:false |
delay | number | 是 | 防抖延迟(毫秒)。默认:1000 |
BuildConfig
构建配置。electron 键必须是 BundleConfig;其他所有键为 ExecConfig。
typescript
interface BuildConfig {
electron: BundleConfig;
[key: string]: ExecConfig | BundleConfig | undefined;
}BundleConfig
esbuild 打包配置 — 控制 Electron 主进程代码打包。
typescript
interface BundleConfig {
bundleType?: 'bundle' | 'copy';
external?: string[];
sourcemap?: boolean | 'inline' | 'external';
minify?: boolean;
drop?: ('console' | 'debugger')[];
keepNames?: boolean;
legalComments?: 'inline' | 'eof' | 'none';
define?: Record<string, string>;
copy?: string[];
format?: 'cjs' | 'esm';
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
bundleType | 'bundle' | 'copy' | 否 | 打包模式。'bundle' = esbuild 单文件打包,'copy' = 目录复制。默认:'bundle' |
external | string[] | 否 | 用户自定义的 esbuild 外部依赖(框架外部依赖自动添加)。默认:[] |
sourcemap | boolean | 'inline' | 'external' | 否 | Sourcemap 配置。false = 自动(开发→inline,生产→关闭)。默认:false |
minify | boolean | 否 | 压缩代码。默认:false |
drop | ('console' | 'debugger')[] | 否 | 要移除的语句类型。默认:[] |
keepNames | boolean | 否 | 压缩时保留函数/类名。默认:false |
legalComments | 'inline' | 'eof' | 'none' | 否 | License 注释处理方式。默认:'none' |
define | Record<string, string> | 否 | 编译时常量(如 { 'process.env.X': '"value"' })。默认:{} |
copy | string[] | 否 | 从 electron/ 中额外复制到输出的文件/目录(脚本转译,其他原样复制)。默认:[] |
format | 'cjs' | 'esm' | 否 | 输出格式。'cjs' 推荐用于 Electron。默认:'cjs' |
Sourcemap 自动模式
当 sourcemap 为 false(默认)时,ee-bin 自动选择:
- 开发环境:inline sourcemap(便于调试)
- 生产环境:无 sourcemap(用于生产发布)
设置为 'inline' 或 'external' 可覆盖此自动行为。
EncryptConfig
加密策略配置,针对前端或 Electron 目标。
typescript
interface EncryptConfig {
type: 'confusion' | 'bytecode' | 'strict' | 'none';
files?: string[];
fileExt?: string[];
specificFiles?: string[];
entryFiles?: string[];
cleanFiles?: string[];
encryptDir?: string;
silent?: boolean;
confusionOptions?: ConfusionOptions;
bytecodeOptions?: BytecodeOptions;
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
type | 'confusion' | 'bytecode' | 'strict' | 'none' | 是 | 加密类型。见下表 |
files | string[] | 否 | Globby 匹配的待加密文件模式 |
fileExt | string[] | 否 | 仅处理这些扩展名。默认:['.js'] |
specificFiles | string[] | 否 | 在字节码模式下也强制使用混淆的文件(如 preload 脚本) |
entryFiles | string[] | 否 | 必须保持 .js 格式的入口文件(在字节码模式下变为 bytenode 加载壳) |
cleanFiles | string[] | 否 | 加密后要清除的目录路径 |
encryptDir | string | 否 | 加密的基准目录。默认:'./' |
silent | boolean | 否 | 抑制 javascript-obfuscator 推广横幅。默认:false |
confusionOptions | ConfusionOptions | 否 | 混淆选项(仅用于 confusion / strict 类型) |
bytecodeOptions | BytecodeOptions | 否 | 字节码编译选项(仅用于 bytecode / strict 类型) |
加密类型:
| 类型 | 说明 | 前端 | Electron |
|---|---|---|---|
confusion | 仅混淆(javascript-obfuscator) | ✅ | ✅ |
bytecode | 仅字节码(bytenode) | ❌ | ✅ |
strict | 混淆 + 字节码组合 | ❌ | ✅ |
none | 不加密 | ✅ | ✅ |
前端字节码
前端仅支持 confusion。字节码编译为 V8 字节码,但浏览器渲染器运行的是与编译时不同的 V8 版本,因此字节码不兼容。
ConfusionOptions
javascript-obfuscator 配置选项。
typescript
interface ConfusionOptions {
compact?: boolean;
stringArray?: boolean;
stringArrayThreshold?: number;
stringArrayEncoding?: Array<'none' | 'base64' | 'rc4'>;
stringArrayCallsTransform?: boolean;
deadCodeInjection?: boolean;
numbersToExpressions?: boolean;
target?: 'browser' | 'node';
}| 字段 | 类型 | 说明 |
|---|---|---|
compact | boolean | 移除换行。默认:true |
stringArray | boolean | 将字符串移至数组。默认:true |
stringArrayThreshold | number | 字符串被移至数组的概率(0–1) |
stringArrayEncoding | Array<'none' | 'base64' | 'rc4'> | 字符串编码方式。'none' = 无编码,'base64' = Base64,'rc4' = RC4 加密 |
stringArrayCallsTransform | boolean | 转换字符串数组调用。默认:true |
deadCodeInjection | boolean | 注入死代码块。默认:false |
numbersToExpressions | boolean | 将数字替换为表达式。默认:true |
target | 'browser' | 'node' | 混淆目标运行环境。前端:'browser',Electron:'node' |
BytecodeOptions
bytenode 编译选项。
typescript
interface BytecodeOptions {
filename?: string;
output?: string;
electron?: boolean;
}| 字段 | 类型 | 说明 |
|---|---|---|
filename | string | 输入源文件路径(由加密模块自动设置) |
output | string | 输出 .jsc 文件路径(默认为 filename + 'c') |
electron | boolean | 为 Electron V8 编译。默认:对 Electron 目标为 true |
MoveConfig
资源移动/复制配置 — 定义源路径和目标路径。
typescript
interface MoveConfig {
src: string;
dest: string;
dist?: string;
target?: string;
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
src | string | 是 | 源路径(相对于项目根目录) |
dest | string | 是 | 目标路径(相对于项目根目录) |
dist | string | 否 | 覆盖 src(设置后优先使用) |
target | string | 否 | 覆盖 dest(设置后优先使用) |
UpdaterConfig
增量更新配置 — 用于生成更新包。
typescript
interface UpdaterConfig {
metadata: string;
appFile?: string;
builderConfig?: string;
output: {
directory: string;
zip: string;
file: string;
};
extraResources?: string[];
asarUnpacked?: string[];
cleanCache?: boolean;
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
metadata | string | 是 | 元数据 YAML 文件路径(版本、发布日期、SHA512 哈希) |
appFile | string | 否 | 应用包路径(asar 或目录)。当 builder 设置 asar:false 时自动去除 .asar 扩展名。可通过 CLI --app-file 覆盖 |
builderConfig | string | 否 | Builder 配置路径(检测 asar:true/false 以自动调整 appFile) |
output.directory | string | 是 | 输出目录 |
output.zip | string | 是 | Zip 文件名模板(平台/版本后缀自动追加) |
output.file | string | 是 | JSON 元数据文件名模板(平台后缀自动追加) |
extraResources | string[] | 否 | 包含到 zip 中的额外资源的 Glob 模式 |
asarUnpacked | string[] | 否 | 从 asarUnpacked 中包含到 zip 的原生模块列表 |
cleanCache | boolean | 否 | 生成后清除各平台临时目录 |
OhosConfig
鸿蒙资源提取配置。
typescript
interface OhosConfig {
resources: OhosResourceConfig[];
}OhosResourceConfig
单个资源条目 — 遵循 electron-builder 的 FileSet 模式。
typescript
interface OhosResourceConfig {
from: string;
to: string;
filter?: string[];
}| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
from | string | 是 | 源路径(相对于项目根目录) |
to | string | 是 | 目标路径(相对于项目根目录) |
filter | string[] | 否 | Glob 过滤模式,支持否定语法(如 "!compiled")。默认:["**/*"] |
