elec_rag_ui/electron-builder.config.ts
ssurui 16a19a12f5 fix: 修正 electron-builder 打包 ASR 模型资源的相对路径
extraResources 中 ASR 模型的 from 路径沿用了旧项目两层嵌套目录结构,
在当前扁平的 elec_rag_ui 项目中指向不存在的路径,导致打包产物缺失
语音识别模型文件。

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-08-15 20:07:03 +08:00

69 lines
2.1 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { Configuration } from 'electron-builder'
import { execSync } from 'child_process'
import { readFileSync } from 'fs'
import { resolve } from 'path'
const releaseVersion = (() => {
try {
const tag = execSync('git describe --tags --abbrev=0').toString().trim()
return tag.replace(/^v/, '')
} catch {
// 无 git 环境(PAD rsync 部署):读取 .app-version 文件
try {
const tag = readFileSync(resolve('.app-version'), 'utf-8').trim()
return tag.replace(/^v/, '')
} catch {
return '0.0.0'
}
}
})()
const config: Configuration = {
appId: 'com.elec-rag-ui.app',
extraMetadata: { version: releaseVersion },
productName: '智能电子手册',
directories: {
buildResources: 'resources',
output: 'dist'
},
files: ['out/**/*'],
asarUnpack: [
'node_modules/@lancedb/**',
'node_modules/apache-arrow/**',
'node_modules/onnxruntime-node/**',
'node_modules/sherpa-onnx-node/**',
'node_modules/sherpa-onnx-linux-x64/**'
],
// 打包时内嵌模型:LOCAL_MODEL_PATH=/path/to/bge-small-zh-v1.5 npm run package:mac
extraResources: [
...(process.env.LOCAL_MODEL_PATH
? [{ from: process.env.LOCAL_MODEL_PATH, to: 'models/bge-small-zh-v1.5' }]
: []),
{
from: 'models/asr/sherpa-onnx-streaming-paraformer-bilingual-zh-en',
to: 'models/asr/sherpa-onnx-streaming-paraformer-bilingual-zh-en'
},
// 内嵌离线 TTS 引擎(espeak-ng + 数据 + 依赖库),避免目标系统无 speech-dispatcher/espeak
{
from: 'resources/tts',
to: 'tts'
}
],
linux: {
// Linux 禁用 asar:sherpa-onnx-node 通过相对路径加载 sherpa-onnx-linux-x64 原生模块,
// 在 asar 归档内 __dirname 指向虚拟路径,导致 require 无法定位 .node 文件。
asar: false,
target: [
{ target: 'AppImage', arch: ['x64', 'arm64'] },
{ target: 'deb', arch: ['x64', 'arm64'] }
],
category: 'Utility'
},
// 加快 deb 打包速度:gzip 比 xz 快很多,体积略大
deb: {
compression: 'gz' as const
}
}
export default config