-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
134 lines (120 loc) · 3.79 KB
/
vite.config.ts
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
import path from 'path'
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Inspect from 'vite-plugin-inspect'
import { visualizer } from 'rollup-plugin-visualizer'
import { svgBuilder } from './plugins/svg'
import mockPlugin from './plugins/mock'
const pathSrc = path.resolve(__dirname, 'src')
export default defineConfig(({ command }) => {
const isBuild = command === 'build'
const devPlugins = []
if (!isBuild) {
devPlugins.push()
}
return {
base: '/vue3-admin-typescript-vite/',
optimizeDeps: {
include: [],
},
resolve: {
alias: {
'@': pathSrc,
},
},
plugins: [
mockPlugin(command),
Vue(),
svgBuilder('./src/icons/svg/'),
AutoImport({
// Auto import functions from Vue, e.g. ref, reactive, toRef...
// 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
imports: ['vue', 'vue-router'],
// Auto import functions from Element Plus, e.g. ElMessage, ElMessageBox... (with style)
// 自动导入 Element Plus 相关函数,如:ElMessage, ElMessageBox... (带样式)
resolvers: [
ElementPlusResolver({ importStyle: 'sass', directives: true }),
// Auto import icon components
// 自动导入图标组件
IconsResolver({
prefix: 'Icon',
}),
],
// Auto import for all module exports under directories
dirs: ['src/store/modules'],
dts: true,
// Generate corresponding .eslintrc-auto-import.json file.
// eslint globals Docs - https://eslint.org/docs/user-guide/configuring/language-options#specifying-globals
eslintrc: {
enabled: true, // Default `false`
filepath: './.eslintrc-auto-import.json', // Default `./.eslintrc-auto-import.json`
globalsPropValue: true, // Default `true`, (true | false | 'readonly' | 'readable' | 'writable' | 'writeable')
},
}),
Components({
resolvers: [
// Auto register icon components https://icones.js.org/
// 自动注册图标组件
IconsResolver({
enabledCollections: ['ep', 'ic'],
}),
// Auto register Element Plus components
// 自动导入 Element Plus 组件
ElementPlusResolver({ importStyle: 'sass', directives: true }),
],
dts: true,
}),
Icons({
scale: 1,
autoInstall: true,
}),
Inspect(),
],
build: {
cssCodeSplit: false,
minify: 'terser',
/** 在 build 代码时移除 console.log、debugger 和 注释 */
terserOptions: {
compress: {
drop_console: false,
drop_debugger: true,
pure_funcs: ['console.log'],
},
output: {
comments: false,
},
},
rollupOptions: {
plugins: [
visualizer(() => {
return {
filename: path.join('dist', 'stats.html'),
gzipSize: true,
}
}),
],
manualChunks(id) {
if (
id.includes('mock') ||
id.includes('sortablejs') ||
id.includes('lodash') ||
id.includes('@vue') ||
id.includes('@vue') ||
id.includes('nprogress') ||
id.includes('pinia') ||
id.includes('axios') ||
id.includes('vue-router') ||
id.includes('clipboard')
) {
return 'lib'
}
},
},
},
}
})