Files
kitchen-desktop/electron.vite.config.mjs
2025-12-01 10:49:30 +08:00

81 lines
2.2 KiB
JavaScript
Raw 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 { resolve } from 'path'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import { loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd(), "")
const rendererSrc = resolve(__dirname, 'src/renderer/src')
return {
main: {
plugins: [externalizeDepsPlugin()]
},
preload: {
plugins: [externalizeDepsPlugin()]
},
renderer: {
// 保持并合并原 vite 配置proxy、resolve、esbuild 等)
server: {
hmr: { enabled: true },
proxy: {
'/api': {
target: env.VITE_API_URL,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ''),
},
'/php': {
target: env.VITE_API_PHP_URL,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/php/, ''),
},
'/kp': {
target: env.VITE_API_KP_URL,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/kp/, ''),
},
},
},
resolve: {
alias: {
'@renderer': rendererSrc,
'@': rendererSrc,
},
extensions: ['.vue', '.js', '.jsx', '.json'],
preserveSymlinks: true,
ignoreCase: false,
},
plugins: [
vue(),
// 自动导入 Composition API、vue-router 等,生成类型声明到 src/auto-imports.d.ts
AutoImport({
imports: [
'vue',
'vue-router',
{
'element-plus': [
'ElMessage',
'ElMessageBox',
'ElNotification',
'ElLoading'
]
}
],
dts: 'src/auto-imports.d.ts',
// 生成 ESLint 全局变量配置,防止 ESLint 报未定义
eslintrc: {
enabled: true,
filepath: './.eslintrc-auto-import.json',
globalsPropValue: true
}
}),
],
esbuild: {
drop: env.ENV == 'production' ? ['console'] : [],
},
},
}
})