-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.js
More file actions
94 lines (89 loc) · 2.3 KB
/
vite.config.js
File metadata and controls
94 lines (89 loc) · 2.3 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
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import tailwindcss from '@tailwindcss/vite'
import { resolve } from 'path'
import viteCompression from 'vite-plugin-compression'
import { visualizer } from 'rollup-plugin-visualizer'
// https://vite.dev/config/
export default defineConfig(({ command, mode }) => {
// 根据当前工作目录中的 `mode` 加载 .env 文件
const env = loadEnv(mode, process.cwd())
const isAnalyze = mode === 'analyze'
const plugins = [
vue(),
AutoImport({
resolvers: [ElementPlusResolver()],
imports: ['vue', 'vue-router']
}),
Components({
resolvers: [ElementPlusResolver()],
}),
tailwindcss(),
// gzip压缩
viteCompression({
verbose: true,
disable: false,
threshold: 10240,
algorithm: 'gzip',
ext: '.gz',
}),
]
// 在分析模式下添加可视化插件
if (isAnalyze) {
plugins.push(
visualizer({
open: true,
filename: 'stats.html',
gzipSize: true,
brotliSize: true,
})
)
}
return {
plugins,
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
},
build: {
// 启用压缩
minify: 'terser',
terserOptions: {
compress: {
// 移除 console
drop_console: true,
drop_debugger: true,
},
},
// 分块策略
rollupOptions: {
output: {
chunkFileNames: 'assets/js/[name]-[hash].js',
entryFileNames: 'assets/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
manualChunks: {
vue: ['vue', 'vue-router'],
elementPlus: ['element-plus'],
echarts: ['echarts'],
}
}
},
// 启用 CSS 代码分割
cssCodeSplit: true,
// 启用源码映射(生产环境可以设为 false)
sourcemap: false,
// 设置块大小警告的限制(单位:kb)
chunkSizeWarningLimit: 1000
},
server: {
port: 3000,
open: true,
cors: true,
},
base: '/eng-dev'
}
})