Skip to content

简介

ee-bin 配置的完整类型定义。./cmd/bin.js 文件遵循 BinConfig 接口结构,ee-bin 会将其与 bin_default.ts 的默认值深度合并,生成最终配置。

参见默认值 | bin CLI

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;
}
字段类型必填说明
devDevConfig开发模式子进程配置(前端 + Electron)
buildBuildConfig构建配置(Electron 打包 + 平台打包)
moveRecord<string, MoveConfig>资源移动配置(如前端 dist → public/dist)
startExecConfig生产启动配置
encryptRecord<string, EncryptConfig>加密配置(前端 + Electron,各自独立)
execRecord<string, ExecConfig>自定义命令配置(默认为空,用户自定义)
updaterRecord<string, UpdaterConfig>增量更新配置(按平台)
ohosOhosConfig鸿蒙资源提取配置

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;
}
字段类型必填说明
directorystring进程工作目录(相对于项目根目录)
cmdstring要执行的命令(如 npmelectronelectron-builder
argsstring[]命令参数数组
stdio'inherit' | 'pipe' | 'ignore'子进程 stdio 模式。默认:'inherit'
syncboolean同步执行。默认:false
protocolstring前端协议。'http://' = 开发服务器,'file://' = 跳过前端
watchboolean监听文件变更并自动重启(仅 Electron)。默认:false
delaynumber监听模式的防抖延迟(毫秒)。默认:1000
hostnamestring前端开发服务器主机名
portnumber前端开发服务器端口
indexPathstring前端首页文件名
forceboolean强制刷新页面。默认:false
loadingPagestringElectron 加载页路径(在主内容之前显示加载页)

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;
}
字段类型必填说明
directorystring前端目录。默认:'./frontend'
cmdstring命令。默认:'npm'
argsstring[]参数。默认:['run', 'dev']
protocolstring协议。默认:'http://'
hostnamestring主机名。默认:'localhost'
portnumber端口。默认:8080
indexPathstring首页。默认:'index.html'
forceboolean强制刷新。默认:false
syncboolean同步模式。默认:false

DevElectronConfig

继承 ExecConfig,为 Electron 进程预设必填默认值。

typescript
interface DevElectronConfig extends ExecConfig {
  args: string[];
  loadingPage: string;
  watch: boolean;
  sync: boolean;
  delay: number;
}
字段类型必填说明
directorystring目录。默认:'./'
cmdstring命令。默认:'electron'
argsstring[]参数。默认:['.', '--env=local']
loadingPagestring加载页路径。默认:''/public/html/loading.html'
watchboolean监听模式。默认:false
syncboolean同步模式。默认:false
delaynumber防抖延迟(毫秒)。默认: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'
externalstring[]用户自定义的 esbuild 外部依赖(框架外部依赖自动添加)。默认:[]
sourcemapboolean | 'inline' | 'external'Sourcemap 配置。false = 自动(开发→inline,生产→关闭)。默认:false
minifyboolean压缩代码。默认:false
drop('console' | 'debugger')[]要移除的语句类型。默认:[]
keepNamesboolean压缩时保留函数/类名。默认:false
legalComments'inline' | 'eof' | 'none'License 注释处理方式。默认:'none'
defineRecord<string, string>编译时常量(如 { 'process.env.X': '"value"' })。默认:{}
copystring[]electron/ 中额外复制到输出的文件/目录(脚本转译,其他原样复制)。默认:[]
format'cjs' | 'esm'输出格式。'cjs' 推荐用于 Electron。默认:'cjs'

Sourcemap 自动模式

sourcemapfalse(默认)时,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'加密类型。见下表
filesstring[]Globby 匹配的待加密文件模式
fileExtstring[]仅处理这些扩展名。默认:['.js']
specificFilesstring[]在字节码模式下也强制使用混淆的文件(如 preload 脚本)
entryFilesstring[]必须保持 .js 格式的入口文件(在字节码模式下变为 bytenode 加载壳)
cleanFilesstring[]加密后要清除的目录路径
encryptDirstring加密的基准目录。默认:'./'
silentboolean抑制 javascript-obfuscator 推广横幅。默认:false
confusionOptionsConfusionOptions混淆选项(仅用于 confusion / strict 类型)
bytecodeOptionsBytecodeOptions字节码编译选项(仅用于 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';
}
字段类型说明
compactboolean移除换行。默认:true
stringArrayboolean将字符串移至数组。默认:true
stringArrayThresholdnumber字符串被移至数组的概率(0–1)
stringArrayEncodingArray<'none' | 'base64' | 'rc4'>字符串编码方式。'none' = 无编码,'base64' = Base64,'rc4' = RC4 加密
stringArrayCallsTransformboolean转换字符串数组调用。默认:true
deadCodeInjectionboolean注入死代码块。默认:false
numbersToExpressionsboolean将数字替换为表达式。默认:true
target'browser' | 'node'混淆目标运行环境。前端:'browser',Electron:'node'

BytecodeOptions

bytenode 编译选项。

typescript
interface BytecodeOptions {
  filename?: string;
  output?: string;
  electron?: boolean;
}
字段类型说明
filenamestring输入源文件路径(由加密模块自动设置)
outputstring输出 .jsc 文件路径(默认为 filename + 'c'
electronboolean为 Electron V8 编译。默认:对 Electron 目标为 true

MoveConfig

资源移动/复制配置 — 定义源路径和目标路径。

typescript
interface MoveConfig {
  src: string;
  dest: string;
  dist?: string;
  target?: string;
}
字段类型必填说明
srcstring源路径(相对于项目根目录)
deststring目标路径(相对于项目根目录)
diststring覆盖 src(设置后优先使用)
targetstring覆盖 dest(设置后优先使用)

UpdaterConfig

增量更新配置 — 用于生成更新包。

typescript
interface UpdaterConfig {
  metadata: string;
  appFile?: string;
  builderConfig?: string;
  output: {
    directory: string;
    zip: string;
    file: string;
  };
  extraResources?: string[];
  asarUnpacked?: string[];
  cleanCache?: boolean;
}
字段类型必填说明
metadatastring元数据 YAML 文件路径(版本、发布日期、SHA512 哈希)
appFilestring应用包路径(asar 或目录)。当 builder 设置 asar:false 时自动去除 .asar 扩展名。可通过 CLI --app-file 覆盖
builderConfigstringBuilder 配置路径(检测 asar:true/false 以自动调整 appFile
output.directorystring输出目录
output.zipstringZip 文件名模板(平台/版本后缀自动追加)
output.filestringJSON 元数据文件名模板(平台后缀自动追加)
extraResourcesstring[]包含到 zip 中的额外资源的 Glob 模式
asarUnpackedstring[]从 asarUnpacked 中包含到 zip 的原生模块列表
cleanCacheboolean生成后清除各平台临时目录

OhosConfig

鸿蒙资源提取配置。

typescript
interface OhosConfig {
  resources: OhosResourceConfig[];
}

OhosResourceConfig

单个资源条目 — 遵循 electron-builder 的 FileSet 模式。

typescript
interface OhosResourceConfig {
  from: string;
  to: string;
  filter?: string[];
}
字段类型必填说明
fromstring源路径(相对于项目根目录)
tostring目标路径(相对于项目根目录)
filterstring[]Glob 过滤模式,支持否定语法(如 "!compiled")。默认:["**/*"]