Files
terminal-lab/terminal/apps/web/vite.config.ts
douboer@gmail.com 3b7c1d558a first commit
2026-03-03 13:23:14 +08:00

54 lines
1.4 KiB
TypeScript
Raw Permalink 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 { fileURLToPath, URL } from "node:url";
import fs from "node:fs";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
const DEV_HOST = "0.0.0.0";
const DEV_PORT = 5173;
const DEV_PUBLIC_HOST = "shell.biboer.cn";
const DEV_CERT_PATH = "/Users/gavin/.acme.sh/shell.biboer.cn_ecc/fullchain.cer";
const DEV_KEY_PATH = "/Users/gavin/.acme.sh/shell.biboer.cn_ecc/shell.biboer.cn.key";
function resolveDevHttpsConfig() {
// 优先复用 acme.sh 证书,确保本地开发服务直接以 HTTPS 暴露。
if (!fs.existsSync(DEV_CERT_PATH) || !fs.existsSync(DEV_KEY_PATH)) {
return undefined;
}
return {
cert: fs.readFileSync(DEV_CERT_PATH),
key: fs.readFileSync(DEV_KEY_PATH)
};
}
export default defineConfig({
plugins: [vue()],
server: {
host: DEV_HOST,
port: DEV_PORT,
strictPort: true,
https: resolveDevHttpsConfig(),
// 允许通过外网域名访问 dev server含 HMR websocket 握手)。
allowedHosts: [DEV_PUBLIC_HOST],
// 明确 HMR 走外网域名,避免客户端回退到 localhost 导致连接拒绝。
hmr: {
protocol: "wss",
host: DEV_PUBLIC_HOST,
clientPort: DEV_PORT,
port: DEV_PORT
},
proxy: {
"/ws/terminal": {
target: "ws://127.0.0.1:8787",
ws: true,
changeOrigin: true
}
}
},
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url))
}
}
});