2026-04-03 20:55:51 +08:00
|
|
|
|
import { defineConfig } from 'vite'
|
|
|
|
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
|
|
import { fileURLToPath, URL } from 'node:url'
|
|
|
|
|
|
|
|
|
|
|
|
// HTTPS: 启动时加 --https 参数,或设环境变量 VITE_HTTPS=true
|
|
|
|
|
|
// 默认 HTTP(局域网测试友好,无证书问题)
|
|
|
|
|
|
const useHttps = process.argv.includes('--https') || process.env.VITE_HTTPS === 'true'
|
|
|
|
|
|
let sslPlugin = []
|
|
|
|
|
|
if (useHttps) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const basicSsl = (await import('@vitejs/plugin-basic-ssl')).default
|
|
|
|
|
|
sslPlugin = [basicSsl()]
|
|
|
|
|
|
} catch { /* basicSsl not installed, skip */ }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
|
|
plugins: [vue(), ...sslPlugin],
|
|
|
|
|
|
resolve: {
|
|
|
|
|
|
alias: {
|
|
|
|
|
|
'@': fileURLToPath(new URL('./src', import.meta.url))
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
server: {
|
|
|
|
|
|
port: 3001,
|
|
|
|
|
|
host: '0.0.0.0',
|
|
|
|
|
|
proxy: {
|
|
|
|
|
|
'/api': {
|
2026-04-07 12:11:15 +08:00
|
|
|
|
target: 'http://localhost:8080',
|
2026-04-03 20:55:51 +08:00
|
|
|
|
changeOrigin: true
|
|
|
|
|
|
},
|
|
|
|
|
|
'/ws': {
|
2026-04-07 12:11:15 +08:00
|
|
|
|
target: 'http://localhost:8080',
|
2026-04-03 20:55:51 +08:00
|
|
|
|
ws: true
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|