-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
191 lines (180 loc) · 5.14 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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import vueJsx from '@vitejs/plugin-vue-jsx'
import Unocss from 'unocss/vite'
import presetIcons from '@unocss/preset-icons'
import presetUno from '@unocss/preset-uno'
import presetAttributify from '@unocss/preset-attributify'
export default defineConfig(({ command, mode }) => {
if (command === 'serve') {
return {
plugins: [
vue(),
AutoImport({
// targets to transform
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/, // .vue
/\.md$/, // .md
],
// 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(),
// Auto import icon components
// 自动导入图标组件
IconsResolver({
prefix: 'Icon',
}),
],
dirs: ['./utils'],
dts: true,
}),
Components({
resolvers: [
ElementPlusResolver(),
// Auto register icon components
// 自动注册图标组件
IconsResolver(),
],
}),
Icons({
autoInstall: true,
}),
vueJsx(),
Unocss({
presets: [
presetIcons({
/* options */
}),
// ...other presets
presetUno(),
presetAttributify(),
],
}),
],
resolve: {
alias: {
'@': resolve(__dirname, './src'),
},
},
css: {
modules: {
scopeBehaviour: 'local',
},
preprocessorOptions: {
// less: {
// charset: false,
// javascriptEnabled: true,
// additionalData: `@import "${path.resolve(__dirname, './src/styles/variable.less')}";`,
// },
// less: {
// modifyVars: {
// hack: `true; @import "${path.resolve(__dirname, './src/styles/variable.less')}";`,
// },
// javascriptEnabled: true
// }
},
},
define: {
__DEV__: true,
},
server: {
port: 4001,
},
// 部署时设置
// base: '/NeteaseCloudMusic-Website/'
}
} else if (command === 'build') {
return {
plugins: [
vue(),
AutoImport({
// targets to transform
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/, // .vue
/\.md$/, // .md
],
// 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(),
// Auto import icon components
// 自动导入图标组件
IconsResolver({
prefix: 'Icon',
}),
],
dirs: ['./utils'],
dts: true,
}),
Components({
resolvers: [
ElementPlusResolver(),
// Auto register icon components
// 自动注册图标组件
IconsResolver(),
],
}),
Icons({
autoInstall: true,
}),
vueJsx(),
Unocss({
presets: [
presetIcons({
/* options */
}),
// ...other presets
presetUno(),
presetAttributify(),
],
}),
],
resolve: {
alias: {
'@': resolve(__dirname, './src'),
},
},
css: {
modules: {
scopeBehaviour: 'local',
},
preprocessorOptions: {
// less: {
// charset: false,
// javascriptEnabled: true,
// additionalData: `@import "${path.resolve(__dirname, './src/styles/variable.less')}";`,
// },
// less: {
// modifyVars: {
// hack: `true; @import "${path.resolve(__dirname, './src/styles/variable.less')}";`,
// },
// javascriptEnabled: true
// }
},
},
define: {
__DEV__: false,
},
server: {
port: 4001,
},
}
}
})