-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.js
More file actions
163 lines (150 loc) · 3.71 KB
/
Copy pathvite.config.js
File metadata and controls
163 lines (150 loc) · 3.71 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import {
defineConfig
} from 'vite'
import vue2 from '@vitejs/plugin-vue2'
import {
visualizer
} from 'rollup-plugin-visualizer'
import viteImagemin from 'vite-plugin-imagemin'
import {
fileURLToPath,
URL
} from 'node:url'
export default defineConfig({
plugins: [
vue2(),
// 图片优化
viteImagemin({
gifsicle: {
optimizationLevel: 7,
interlaced: false
},
mozjpeg: {
quality: 75,
progressive: true
},
pngquant: {
quality: [0.65, 0.8],
speed: 4
},
svgo: {
plugins: [
{
name: 'removeViewBox'
},
{
name: 'removeEmptyAttrs',
active: false
}
]
}
}),
// 包分析工具
visualizer({
filename: 'dist/stats.html',
open: false,
gzipSize: true
})
],
// 开发服务器配置
server: {
port: 5000,
open: true,
host: true,
proxy: {
'/api': {
target: 'http://127.0.0.1:8888',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, '')
}
}
},
// 路径别名
resolve: {
alias: {
'@': fileURLToPath(new URL('./src',
import.meta.url))
}
},
// 构建配置
build: {
sourcemap: false,
outDir: 'dist',
assetsDir: 'static',
rollupOptions: {
output: {
// 更精细的代码分割策略
manualChunks: (id) => {
// Vue 核心库(优先级最高,单独打包)
if (id.includes('vue/dist') || id.includes('vue-router') || id.includes('vuex')) {
return 'vue-vendor'
}
// Element UI(体积较大,单独分包)
if (id.includes('element-ui')) {
return 'element-ui'
}
// ECharts(按模块细分)
if (id.includes('echarts')) {
if (id.includes('echarts/core') || id.includes('echarts/charts')) {
return 'echarts-core'
}
if (id.includes('echarts/components') || id.includes('echarts/renderers')) {
return 'echarts-components'
}
return 'echarts'
}
// MediaPipe(AI相关,使用频率不高)
if (id.includes('@mediapipe/')) {
return 'mediapipe'
}
// 工具库(高频使用,合并打包)
if (id.includes('axios') || id.includes('dayjs') || id.includes('nprogress') || id.includes('qs')) {
return 'utils'
}
// 文件处理相关
if (id.includes('spark-md5') || id.includes('vue-cropper')) {
return 'file-tools'
}
// 其他UI/交互工具
if (id.includes('screenfull') || id.includes('promise-queue-plus')) {
return 'ui-tools'
}
// 其他第三方库
if (id.includes('node_modules')) {
return 'vendors'
}
},
// 资源文件命名
assetFileNames: (assetInfo) => {
const ext = assetInfo.name.split('.').pop()
if (/\.(png|jpe?g|gif|svg)$/i.test(assetInfo.name)) {
return `img/[name]-[hash].${ext}`
}
if (/\.(woff2?|eot|ttf|otf)$/i.test(assetInfo.name)) {
return `fonts/[name]-[hash].${ext}`
}
return `static/[name]-[hash].${ext}`
}
}
},
chunkSizeWarningLimit: 1000
},
// CSS配置
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true
}
}
},
// 定义全局变量
define: {
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: false,
'process.env': {}
},
// Worker配置
worker: {
format: 'es'
}
})