-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathvite.config.ts
More file actions
86 lines (85 loc) · 2.41 KB
/
Copy pathvite.config.ts
File metadata and controls
86 lines (85 loc) · 2.41 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
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import * as path from 'path'
export default defineConfig({
plugins: [
vue(),
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
// 指定symbolId格式
symbolId: 'icon-[dir]-[name]'
})
],
build: {
target: ['edge90', 'chrome90', 'firefox90', 'safari15'],
// 启用 CSS 代码分割
cssCodeSplit: true,
// 构建后是否生成 source map 文件
sourcemap: false,
// chunk 大小警告的限制(单位:kbs)
chunkSizeWarningLimit: 1000,
rollupOptions: {
output: {
// 静态资源分类打包
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
// 代码分割策略
manualChunks: {
// 将 Vue 相关库单独打包
'vue-vendor': ['vue', 'vue-router', 'pinia'],
// UI 组件库
'ui-vendor': ['@headlessui/vue', '@heroicons/vue'],
// Markdown 解析(首屏同步依赖)
'libs-vendor': ['marked'],
// 图片生成库(仅在导出图片时动态加载,须独立分包以避免进入首屏)
'snapdom': ['@zumer/snapdom']
}
}
},
// 生产环境压缩配置
minify: 'esbuild'
},
// esbuild 特有配置:移除 console 和 debugger
esbuild: {
drop: ['console', 'debugger']
},
resolve: {
// 配置路径别名
alias: {
'@': path.resolve(__dirname, './src'),
'@assets': path.resolve(__dirname, './src/assets'),
'@components': path.resolve(__dirname, './src/components'),
'@views': path.resolve(__dirname, './src/views'),
'@stores': path.resolve(__dirname, './src/stores'),
'@helper': path.resolve(__dirname, './src/helper')
}
},
worker: {
format: 'es'
},
// 优化依赖预构建
optimizeDeps: {
include: [
'vue',
'vue-router',
'pinia',
'marked',
'@headlessui/vue'
]
},
// 性能优化
server: {
// 预热常用文件
warmup: {
clientFiles: [
'./src/views/Home.vue',
'./src/views/Digest.vue',
'./src/views/Quote.vue',
'./src/components/**/*.vue'
]
}
}
})