-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathvite.config.ts
More file actions
104 lines (99 loc) · 2.98 KB
/
Copy pathvite.config.ts
File metadata and controls
104 lines (99 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { readFileSync } from 'node:fs'
import { resolveUmamiWebsiteId, UMAMI_SCRIPT_SRC } from './scripts/umami-analytics.mjs'
const isTauriDev = Boolean(process.env.TAURI_ENV_PLATFORM || process.env.TAURI_DEV_HOST)
const { version: appVersion } = JSON.parse(
readFileSync(new URL('./package.json', import.meta.url), 'utf8'),
) as { version: string }
export default defineConfig({
plugins: [
vue(),
{
name: 'emit-app-version-manifest',
apply: 'build',
generateBundle() {
this.emitFile({
type: 'asset',
fileName: 'version.json',
source: JSON.stringify({ version: appVersion }) + '\n',
})
},
},
// 仅在浏览器构建注入 Umami 统计脚本,index.html 本身保持无远程脚本
{
name: 'inject-umami-analytics',
transformIndexHtml() {
const websiteId = resolveUmamiWebsiteId(process.env)
if (!websiteId) return []
return [
{
tag: 'script',
injectTo: 'head' as const,
attrs: {
async: true,
src: UMAMI_SCRIPT_SRC,
'data-website-id': websiteId,
},
},
]
},
},
// 自定义插件:强制忽略 "pkgs copy" 目录下的模块
{
name: 'ignore-pkgs-copy',
resolveId(source, importer) {
// 如果导入来源(importer)位于 "pkgs copy" 目录内,直接返回 false 表示外部
if (importer && importer.replace(/\\/g, '/').includes('pkgs copy')) {
return { id: source, external: true }
}
return null
},
},
],
base: '/',
server: {
port: 5173,
open: !isTauriDev,
watch: {
// 让文件监视器忽略该目录,避免重启和扫描
ignored: ['**/sample/**'],
},
},
optimizeDeps: {
// 限制依赖预构建的入口范围,避免 Vite 扫描到那个目录
entries: [
'src/**/*.{js,ts,jsx,tsx,vue}',
'index.html',
// 如果你的项目还有其他入口(如 main.ts),可以继续加
],
},
worker: {
format: 'es',
},
build: {
outDir: 'dist',
assetsDir: 'assets',
modulePreload: false,
sourcemap: false,
rollupOptions: {
output: {
manualChunks(id) {
const normalizedId = id.replace(/\\/g, '/')
if (!normalizedId.includes('/node_modules/')) return undefined
if (normalizedId.includes('/node_modules/vue/')) return 'vue-vendor'
if (normalizedId.includes('/node_modules/naive-ui/')) return 'naive-ui'
if (normalizedId.includes('/node_modules/elkjs/')) return 'elkjs'
if (
normalizedId.includes('/node_modules/highlight.js/') ||
normalizedId.includes('/node_modules/vue-virtual-scroller/')
) {
return 'vendor'
}
return undefined
},
},
},
chunkSizeWarningLimit: 1000,
},
})