-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
86 lines (83 loc) · 2.29 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
import { fileURLToPath, URL } from 'node:url';
import { defineConfig, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import AutoImport from 'unplugin-auto-import/vite';
import IconsResolver from 'unplugin-icons/resolver';
import Components from 'unplugin-vue-components/vite';
import Icons from 'unplugin-icons/vite';
import {
ElementPlusResolver,
VueUseComponentsResolver
} from 'unplugin-vue-components/resolvers';
export default defineConfig(({ command, mode }) => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const isBuild = command === 'build';
// 读取env配置文件
const env = loadEnv(mode, process.cwd());
return {
plugins: [
vue(),
// api按需导入
AutoImport({
// 定义element-plus api按需加载
resolvers: [ElementPlusResolver()],
// 导入vue以及其他 api按需加载
imports: ['vue', 'vue-router', 'pinia'],
// 目录文件按需加载
dirs: ['src/enums/**/*', 'src/stores/**/*'],
vueTemplate: true,
// 类型文件输出目录
dts: 'src/types/auto-imports.d.ts'
}),
// 自动导入组件
Components({
resolvers: [
// Element plus组件自动导入
ElementPlusResolver(),
// Vue组件自动导入
VueUseComponentsResolver(),
// 图标自动导入
IconsResolver({
prefix: false,
enabledCollections: ['icon-park-outline'],
alias: {
park: 'icon-park-outline'
}
})
],
extensions: ['vue', 'ts'],
dirs: ['src/components', 'src/layouts'],
// 类型文件输出目录
dts: 'src/types/components.d.ts'
}),
Icons({
autoInstall: true,
compiler: 'vue3'
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@import "./src/assets/styles/var.scss";'
}
}
},
server: {
proxy: {
'/api': {
target: env.VITE_API_URL,
changeOrigin: true
},
'/public': {
target: env.VITE_API_URL,
changeOrigin: true
}
}
}
};
});