54 lines
1.4 KiB
TypeScript
54 lines
1.4 KiB
TypeScript
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))
|
||
}
|
||
}
|
||
});
|