85 lines
2.5 KiB
TypeScript
85 lines
2.5 KiB
TypeScript
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: {
|
|
port: 1420,
|
|
strictPort: true,
|
|
host: host || false,
|
|
hmr: host
|
|
? {
|
|
protocol: "ws",
|
|
host,
|
|
port: 1421,
|
|
}
|
|
: 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/**",
|
|
],
|
|
},
|
|
},
|
|
}));
|