-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
52 lines (50 loc) · 1.64 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
import { fileURLToPath, URL } from 'node:url'
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import { createHtmlPlugin } from 'vite-plugin-html'
import path from 'path'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
//这个配置 为了在html中使用 环境变量
const getViteEnv = (mode, target) => {
return loadEnv(mode, process.cwd())[target];
};
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
//检查process.cwd()路径下.env.development.local、.env.development、.env.local、.env这四个环境文件
loadEnv(mode, process.cwd())
return {
plugins: [
vue(),
vueJsx(),
AutoImport({
resolvers: [ElementPlusResolver()]
}),
Components({
resolvers: [ElementPlusResolver()]
}),
createSvgIconsPlugin({
// 需要自动导入的 svg 文件目录(可自行修改)我的路径如下图所示
iconDirs: [path.resolve(process.cwd(), 'src/assets/icon')],
// 执行icon name的格式(可自行修改)
symbolId: 'icon-[dir]-[name]'
}),
createHtmlPlugin({
inject: {
data: {
logo: getViteEnv(mode, 'VITE_APP_LOGO'),
title: getViteEnv(mode, 'VITE_APP_TITLE')
}
}
})
],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
}
}
})