Files
ChatLab/apps/desktop/electron.vite.config.ts
T
digua 860bf52d62 feat(analytics): add privacy-safe product telemetry
Add self-hosted Umami reporting alongside existing telemetry across Desktop and CLI Web.

Track normalized startup, import, feature, and AI usage with a stable anonymous ID and strict privacy allowlists. Keep incremental usage platform-independent and preserve accurate failure classifications and platform metadata across import paths.
2026-07-29 14:28:48 +08:00

151 lines
5.1 KiB
TypeScript

import { resolve } from 'path'
import { readFileSync } from 'fs'
import { defineConfig } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
import { chatlabIconBundle } from '../../vite.icon-bundle.config'
const rootDir = resolve(__dirname, '../..')
const rootPkg = JSON.parse(readFileSync(resolve(rootDir, 'package.json'), 'utf-8'))
const appVersion: string = rootPkg.version
const openChatLabAliases = {
'@openchatlab/http-routes/auth': resolve(rootDir, 'packages/http-routes/src/auth.ts'),
'@openchatlab/http-routes/errors': resolve(rootDir, 'packages/http-routes/src/errors.ts'),
'@openchatlab/http-routes/import': resolve(rootDir, 'packages/http-routes/src/import/json-push-handler.ts'),
'@openchatlab/http-routes/rest': resolve(rootDir, 'packages/http-routes/src/routes/rest/index.ts'),
'@openchatlab/http-routes/server': resolve(rootDir, 'packages/http-routes/src/server.ts'),
'@openchatlab/node-runtime/import/archive/source-manager': resolve(
rootDir,
'packages/node-runtime/src/import/archive/source-manager.ts'
),
'@openchatlab/node-runtime/data-dir-compat': resolve(rootDir, 'packages/node-runtime/src/data-dir-compat.ts'),
'@openchatlab/node-runtime/data-dir-switch': resolve(rootDir, 'packages/node-runtime/src/data-dir-switch.ts'),
'@openchatlab/node-runtime/temp-workspace': resolve(rootDir, 'packages/node-runtime/src/temp-workspace.ts'),
'@openchatlab': resolve(rootDir, 'packages'),
}
export default defineConfig({
main: {
resolve: {
alias: openChatLabAliases,
},
define: {
__APP_VERSION__: JSON.stringify(appVersion),
'process.env.UMAMI_ENDPOINT': JSON.stringify(process.env.UMAMI_ENDPOINT || ''),
'process.env.UMAMI_WEBSITE_ID': JSON.stringify(process.env.UMAMI_WEBSITE_ID || ''),
// ws 的原生加速依赖是可选项;主进程打包时禁用它们,避免 Vite 将缺失的可选依赖改写为启动即抛错。
'process.env.WS_NO_BUFFER_UTIL': JSON.stringify('true'),
'process.env.WS_NO_UTF_8_VALIDATE': JSON.stringify('true'),
},
build: {
minify: 'esbuild',
rollupOptions: {
input: {
index: resolve(__dirname, 'main/index.ts'),
'worker/dbWorker': resolve(__dirname, 'main/worker/dbWorker.ts'),
'semantic-index-worker': resolve(rootDir, 'packages/node-runtime/src/semantic-index/worker-thread-entry.ts'),
'contacts-worker': resolve(rootDir, 'packages/node-runtime/src/services/contacts/worker-entry.ts'),
'people-relationships-worker': resolve(
rootDir,
'packages/node-runtime/src/services/people/relationships/worker-entry.ts'
),
'global-insight-worker': resolve(
rootDir,
'packages/node-runtime/src/services/global-insight/worker-entry.ts'
),
},
},
},
},
preload: {
resolve: {
alias: openChatLabAliases,
},
build: {
minify: 'esbuild',
rollupOptions: {
input: {
index: resolve(__dirname, 'preload/index.ts'),
},
},
},
},
renderer: {
resolve: {
alias: {
'@': resolve(rootDir, 'src/'),
'~': resolve(rootDir, 'src/'),
...openChatLabAliases,
'@electron': resolve(__dirname),
},
},
define: {
__IS_ELECTRON__: JSON.stringify(true),
},
// 分析页(私聊/群聊)懒加载时才会引入图表/Markdown/截图等重依赖,
// 默认冷启动扫描发现不到,首次进入会触发二次依赖优化,导致已加载 chunk 失效报
// 504 (Outdated Optimize Dep) 并使动态导入页面失败。这里显式预打包,避免运行中再次优化。
optimizeDeps: {
include: [
'echarts/core',
'echarts/charts',
'echarts/components',
'echarts/renderers',
'echarts-wordcloud',
'markdown-it',
'@zumer/snapdom',
'@tanstack/vue-virtual',
'@internationalized/date',
'@vueuse/core',
],
},
plugins: [
vue(),
ui({
ui: {
colors: {
primary: 'pink',
neutral: 'zinc',
},
},
}),
chatlabIconBundle(rootDir),
],
root: resolve(rootDir, 'src/'),
build: {
sourcemap: false,
rollupOptions: {
input: {
index: resolve(rootDir, 'src/index.html'),
},
output: {
manualChunks(id) {
if (id.includes('node_modules/echarts-wordcloud')) {
return 'vendor-echarts-wordcloud'
}
if (id.includes('node_modules/zrender')) {
return 'vendor-zrender'
}
if (id.includes('node_modules/echarts')) {
return 'vendor-echarts'
}
if (id.includes('node_modules/@zumer/snapdom')) {
return 'vendor-snapdom'
}
return undefined
},
},
},
},
server: {
host: '0.0.0.0',
port: 13100,
hmr: {
protocol: 'ws',
host: 'localhost',
port: 13100,
},
},
},
})