cherry-studio/electron.vite.config.ts
GuanMu 6c0b614208
feat: Add code linting plugin support to the Electron configuration (#7740)
* feat: 添加代码检查插件支持到 Electron 配置中,并更新依赖项

* test: Update snapshots to reflect the latest changes in component rendering

- Updated snapshots for DragableList, Scrollbar, CitationTooltip, Markdown, Table, and ThinkingBlock components by adding new data attributes to support debugging and testing.
- Ensured snapshots are consistent with the latest component rendering, improving test accuracy and reliability.

* test: 更新快照以反映组件渲染的最新变化

- 更新了 DragableList、Scrollbar、CitationTooltip、Markdown、Table 和 ThinkingBlock 组件的快照,移除了多余的数据属性以简化调试和测试。
- 确保快照与最新的组件渲染一致,提高了测试的准确性和可靠性。
2025-07-03 10:36:54 +08:00

101 lines
2.8 KiB
TypeScript

import react from '@vitejs/plugin-react-swc'
import { CodeInspectorPlugin } from 'code-inspector-plugin'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import { resolve } from 'path'
import { visualizer } from 'rollup-plugin-visualizer'
const visualizerPlugin = (type: 'renderer' | 'main') => {
return process.env[`VISUALIZER_${type.toUpperCase()}`] ? [visualizer({ open: true })] : []
}
export default defineConfig({
main: {
plugins: [externalizeDepsPlugin(), ...visualizerPlugin('main')],
resolve: {
alias: {
'@main': resolve('src/main'),
'@types': resolve('src/renderer/src/types'),
'@shared': resolve('packages/shared')
}
},
build: {
rollupOptions: {
external: ['@libsql/client', 'bufferutil', 'utf-8-validate'],
output: {
// 彻底禁用代码分割 - 返回 null 强制单文件打包
manualChunks: undefined,
// 内联所有动态导入,这是关键配置
inlineDynamicImports: true
}
},
sourcemap: process.env.NODE_ENV === 'development'
},
optimizeDeps: {
noDiscovery: process.env.NODE_ENV === 'development'
}
},
preload: {
plugins: [externalizeDepsPlugin()],
resolve: {
alias: {
'@shared': resolve('packages/shared')
}
},
build: {
sourcemap: process.env.NODE_ENV === 'development'
}
},
renderer: {
plugins: [
react({
plugins: [
[
'@swc/plugin-styled-components',
{
displayName: true, // 开发环境下启用组件名称
fileName: false, // 不在类名中包含文件名
pure: true, // 优化性能
ssr: false // 不需要服务端渲染
}
]
]
}),
// 只在开发环境下启用 CodeInspectorPlugin
...(process.env.NODE_ENV === 'development'
? [
CodeInspectorPlugin({
bundler: 'vite'
})
]
: []),
...visualizerPlugin('renderer')
],
resolve: {
alias: {
'@renderer': resolve('src/renderer/src'),
'@shared': resolve('packages/shared')
}
},
optimizeDeps: {
exclude: ['pyodide'],
esbuildOptions: {
target: 'esnext' // for dev
}
},
worker: {
format: 'es'
},
build: {
target: 'esnext', // for build
rollupOptions: {
input: {
index: resolve(__dirname, 'src/renderer/index.html'),
miniWindow: resolve(__dirname, 'src/renderer/miniWindow.html'),
selectionToolbar: resolve(__dirname, 'src/renderer/selectionToolbar.html'),
selectionAction: resolve(__dirname, 'src/renderer/selectionAction.html')
}
}
}
}
})