-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.ts
168 lines (150 loc) · 4.41 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
/// <reference types="vitest" />
import path from 'node:path'
import fs from 'node:fs'
import { defineConfig } from 'vite'
import type { CommonServerOptions, ConfigEnv } from 'vite'
import Vue from '@vitejs/plugin-vue'
import UnoCSS from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import PiniaAutoRefs from 'pinia-auto-refs'
import Components from 'unplugin-vue-components/vite'
import { VueRouterAutoImports } from 'unplugin-vue-router'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import VueMacros from 'unplugin-vue-macros/vite'
import VueRouter from 'unplugin-vue-router/vite'
import IconsResolver from 'unplugin-icons/resolver'
import Icons from 'unplugin-icons/vite'
import VueDevtools from 'vite-plugin-vue-devtools'
import { OnuResolver } from 'onu-ui'
import ViteRestart from 'vite-plugin-restart'
import type { DotenvParseOutput } from 'dotenv'
import dotenv from 'dotenv'
// https://vitejs.dev/config/
export default defineConfig((mode: ConfigEnv) => {
const envFileName: string = '.env'
const curEnvFileName = `${envFileName}.${mode.mode}`
let server: CommonServerOptions = {}
const envDate = fs.readFileSync(curEnvFileName)
const envMap: DotenvParseOutput = dotenv.parse(envDate)
server = {
port: Number(envMap.VITE_PORT) || 3891,
host: envMap.VITE_HOST || 'localhost',
proxy: {
[envMap.VITE_BASE_URI || '/api']: {
target: envMap.VITE_PROXY_DOMAIN || 'localhost',
},
},
}
return {
server,
resolve: {
alias: {
'@/': `${path.resolve(__dirname, 'src')}/`,
},
extensions: ['.js', '.json', '.ts', '.vue'],
},
plugins: [
// https://github.com/vue-macros/vue-macros
VueMacros({
defineOptions: false,
defineModels: false,
plugins: {
vue: Vue({
script: {
propsDestructure: true,
defineModel: true,
},
}),
},
}),
ViteRestart({
restart: [
'vite.config.[jt]s',
],
}),
VueDevtools(),
// https://github.com/posva/unplugin-vue-router
VueRouter({
dts: './types/vue-router.d.ts',
}),
// https://github.com/antfu/unplugin-auto-import
AutoImport({
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/, // .vue
/\.md$/, // .md
],
imports: [
'vue',
'pinia',
'@vueuse/core',
VueRouterAutoImports,
{
alova: [
'useRequest',
'useWatcher',
'useFetcher',
],
},
{
'@/helper/pinia-auto-refs': ['useStore'],
'vue-router/auto': ['useLink'],
},
],
// Enable auto import by filename for default module exports under directories
defaultExportByFilename: false,
resolvers: [
// Auto import UI components
// 自动导入ElementPlus组件
ElementPlusResolver(),
// Auto import icon components
// 自动导入图标组件
IconsResolver(),
// Auto import Onu UI components
// 自动导入Onu UI组件
OnuResolver(),
],
dts: './types/auto-imports.d.ts',
dirs: [
'./src/components',
'./src/store',
'./src/composables',
],
vueTemplate: true,
injectAtEnd: true,
}),
// https://github.com/Allen-1998/pinia-auto-refs
PiniaAutoRefs(),
// https://github.com/antfu/vite-plugin-components
Components({
resolvers: [
// Auto register icon components
// 自动注册图标组件
IconsResolver({
enabledCollections: ['ep'],
}),
// Auto register Element Plus components
// 自动导入 Element Plus 组件
ElementPlusResolver(),
// Auto import Onu UI components
// 自动导入Onu UI组件
OnuResolver(),
],
dts: './types/components.d.ts',
include: [/\.vue$/, /\.vue\?vue/, /\.md$/],
}),
// https://github.com/antfu/unocss
// see uno.config.ts for config
UnoCSS(),
Icons({
compiler: 'vue3',
autoInstall: true,
}),
],
// https://github.com/vitest-dev/vitest
test: {
environment: 'jsdom',
},
}
})