-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy pathvite.config.js
More file actions
89 lines (83 loc) · 2.51 KB
/
Copy pathvite.config.js
File metadata and controls
89 lines (83 loc) · 2.51 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
import path from 'node:path'
import process from 'node:process'
import tailwindcss from '@tailwindcss/vite'
import vue from '@vitejs/plugin-vue'
import { visualizer } from 'rollup-plugin-visualizer'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { defineConfig, loadEnv } from 'vite'
import vueDevTools from 'vite-plugin-vue-devtools'
// https://vite.dev/config/
export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), '')
return {
base: '/',
plugins: [
vue(),
// https://github.com/antfu/unplugin-auto-import
AutoImport({
include: [/\.[jt]sx?$/, /\.vue$/, /\.vue\?vue/],
imports: [
'vue',
'@vueuse/core',
],
dts: 'src/auto-imports.d.ts',
dirs: [
'src/composables/**',
'src/utils/**',
],
vueTemplate: true,
}),
// https://github.com/antfu/unplugin-vue-components
Components({
// allow auto load markdown components under `./src/components/`
extensions: ['vue', 'md'],
// allow auto import and register components used in markdown
include: [/\.vue$/, /\.vue\?vue/],
dts: 'src/components.d.ts',
}),
// https://github.com/tailwindlabs/tailwindcss
tailwindcss(),
// https://devtools.vuejs.org/
vueDevTools(),
// https://github.com/btd/rollup-plugin-visualizer
mode === 'analyze' ? visualizer({ open: true, brotliSize: true }) : null,
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
server: {
host: true,
port: Number(env.VITE_APP_DEV_PORT),
},
build: {
chunkSizeWarningLimit: 2048,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return 'vendor'
}
else if (id.includes('src/components')) {
return 'components'
}
return null
},
},
},
minify: 'terser', // 使用 'terser' 获得更好压缩
terserOptions: {
compress: {
drop_console: false, // 在生产环境保留 console,方便调试 Docker 构建问题
drop_debugger: true, // 移除 debugger 语句
pure_funcs: [], // 暂时不移除任何函数调用
},
mangle: {
keep_fnames: true, // 保持函数名,避免某些依赖库出错
},
},
},
}
})