Files
Thing/vite.config.ts
T
2026-08-31 18:05:27 +08:00

87 lines
2.7 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 { defineConfig } from "vite";
import tailwindcss from "@tailwindcss/vite"
import vue from "@vitejs/plugin-vue";
const host = process.env.TAURI_DEV_HOST;
// https://vite.dev/config/
export default defineConfig(async () => ({
plugins: [
vue(),
tailwindcss(),
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url)),
},
},
// 单入口:主窗口
build: {
rollupOptions: {
input: {
main: fileURLToPath(new URL("./index.html", import.meta.url)),
},
// 分包策略:vendor 独立 chunk,业务迭代时不强制重下载依赖
// - vue/pinia/@vueuse: Vue 生态核心,变更频率低
// - reka-ui/@lucide: UI 组件库,体积较大且稳定
// - tauri: Tauri 前端 API,仅在 Tauri 升级时变化
output: {
manualChunks: {
'vue-vendor': ['vue', 'pinia', '@vueuse/core'],
'ui-vendor': ['reka-ui', '@lucide/vue'],
'tauri-vendor': [
'@tauri-apps/api',
'@tauri-apps/plugin-autostart',
'@tauri-apps/plugin-dialog',
'@tauri-apps/plugin-global-shortcut',
'@tauri-apps/plugin-opener',
],
},
},
},
},
// 防止 Vite 缓存 tauri-plugin-snap-layout,否则注入脚本中的占位符无法被替换
optimizeDeps: {
exclude: ["tauri-plugin-snap-layout"],
},
// Vite options tailored for Tauri development and only applied in `tauri dev` or `tauri build`
//
// 1. prevent Vite from obscuring rust errors
clearScreen: false,
// 2. tauri expects a fixed port, fail if that port is not available
server: {
// 1420/1421 落在 Windows 保留端口段 1333-1432 内(Hyper-V/WinNAT 动态保留),
// 绑定时报 EACCES,故改用 14210/14211netsh excludedportrange 确认可用)
port: 14210,
strictPort: true,
host: host || false,
hmr: host
? {
protocol: "ws",
host,
port: 14211,
}
: undefined,
watch: {
// 3. 让 Vite 忽略监听这些大目录,避免 Windows 上 chokidar 递归注册监听句柄
// 拖慢 dev 冷启动。src-tauri/target 是 Rust 构建产物(本仓库可达 5 万+ 文件、
// 数十 GB),默认仅忽略 node_modules/.git/.vite,若被递归遍历,WebView 首屏
// 加载会被阻塞几十秒(详见 juejin.cn/post/7657865700393451554)。
ignored: [
"**/src-tauri/**",
"**/node_modules/**",
"**/dist/**",
"**/release_stage/**",
"**/ThingHK/**",
"**/.git/**",
"**/.idea/**",
"**/.vite/**",
],
},
},
}));