上次提交(d512ad4)里 '!node_modules/onnxruntime-web/**' 这种不带 **/ 前缀的排除规则在真机验证时基本没生效(体积没降)。electron-builder 自动收录 node_modules 的内部匹配逻辑按完整相对路径比对,需要写成 '!**/node_modules/onnxruntime-web/**' 才能正确排除。真机重新打包验证: node_modules 从 597M 降到 373M,符合预期。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
86 lines
3.0 KiB
TypeScript
86 lines
3.0 KiB
TypeScript
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'
|
||
},
|
||
// resources/icon.png 单独列出:src/main/index.ts 用相对路径 __dirname/../../resources/icon.png
|
||
// 定位窗口图标(打包后 __dirname 是 <app>/out/main),必须让它落在 <app>/resources/ 下
|
||
//
|
||
// 排除项:这几个包只在 src/renderer/ 被引用,electron-vite build 时已经被 Vite
|
||
// 静态打包进 out/renderer/*.js,主进程运行时不会去 node_modules 里 require 它们;
|
||
// onnxruntime-web 是 @huggingface/transformers 的硬依赖但项目强制走 onnxruntime-node,
|
||
// 从未被使用。排除后单包体积减少约 227M(naive-ui/date-fns/highlight.js/lodash 系
|
||
// 渲染层已打包、onnxruntime-web 完全未用,详见排查记录)。
|
||
files: [
|
||
'out/**/*',
|
||
'resources/icon.png',
|
||
'!**/node_modules/onnxruntime-web/**',
|
||
'!**/node_modules/naive-ui/**',
|
||
'!**/node_modules/date-fns/**',
|
||
'!**/node_modules/highlight.js/**',
|
||
'!**/node_modules/lodash/**',
|
||
'!**/node_modules/lodash-es/**'
|
||
],
|
||
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
|