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是要执行的命令(如 npm、electron、electron-builder)
argsstring[]否命令参数数组
stdio'inherit' | 'pipe' | 'ignore'否子进程 stdio 模式。默认:'inherit'
syncboolean否同步执行。默认:false
protocolstring否前端协议。'http://' = 开发服务器,'file://' = 跳过前端
watchboolean否监听文件变更并自动重启(仅 Electron)。默认:false
delaynumber否监听模式的防抖延迟(毫秒)。默认:1000
hostnamestring否前端开发服务器主机名
portnumber否前端开发服务器端口
indexPathstring否前端首页文件名
forceboolean否强制刷新页面。默认:false
loadingPagestring否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;
}
字段类型必填说明
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 自动模式

当 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'是加密类型。见下表
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 覆盖
builderConfigstring否Builder 配置路径(检测 asar:true/false 以自动调整 appFile)
output.directorystring是输出目录
output.zipstring是Zip 文件名模板(平台/版本后缀自动追加)
output.filestring是JSON 元数据文件名模板(平台后缀自动追加)
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")。默认:["**/*"]