forked from luckyjolly/vue3-toimc-admin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
126 lines (110 loc) · 3.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
import type { UserConfig, ConfigEnv } from 'vite'
import { resolve } from 'path'
// plugins
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import WindiCSS from 'vite-plugin-windicss'
import vueJsx from '@vitejs/plugin-vue-jsx'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import OptimizationPersist from 'vite-plugin-optimize-persist'
import PkgConfig from 'vite-plugin-package-config'
import vueI18n from '@intlify/vite-plugin-vue-i18n'
// vitejs
import { loadEnv } from 'vite'
import { viteMockServe } from 'vite-plugin-mock'
import { wrapperEnv } from './build/utils'
import pkg from './package.json'
import dayjs from 'dayjs'
import { createProxy } from './build/proxy'
function pathResolve(dir: string) {
return resolve(process.cwd(), '.', dir)
}
// 设置应用信息
const { dependencies, devDependencies, name, version } = pkg
const __APP_INFO__ = {
pkg: { dependencies, devDependencies, name, version },
lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss')
}
// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd()
const env = loadEnv(mode, root)
// loadEnv读取的布尔类型是一个字符串。这个函数可以转换为布尔类型
const viteEnv = wrapperEnv(env)
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE, VITE_HTTPS } = viteEnv
const isBuild = command === 'build'
console.log('🚀 ~ file: vite.config.ts ~ line 28 ~ isBuild', isBuild)
return {
base: VITE_PUBLIC_PATH,
root,
esbuild: {
pure: VITE_DROP_CONSOLE ? ['console.log', 'debugger'] : []
},
server: {
https: VITE_HTTPS,
// Listening on all local IPs
host: true,
port: VITE_PORT,
// Load proxy configuration from .env
proxy: createProxy(VITE_PROXY)
},
plugins: [
vue(),
WindiCSS(),
AutoImport({
imports: ['vue', 'vue-router', '@vueuse/core', '@vueuse/head'],
resolvers: [ElementPlusResolver()],
include: [
/\.[tj]sx?$/, // .ts, .tsx, .js, .jsx
/\.vue$/,
/\.vue\?vue/ // .vue
],
dts: true
}),
Components({
resolvers: [ElementPlusResolver(), IconsResolver()],
dts: true
}),
vueJsx(),
Icons({
autoInstall: true
}),
viteMockServe({
mockPath: './mock',
supportTs: true
}),
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [pathResolve('src/assets/svg')],
// 指定symbolId格式
symbolId: 'icon-[dir]-[name]'
}),
PkgConfig(),
OptimizationPersist(),
// 国际化
vueI18n({
// if you want to use Vue I18n Legacy API, you need to set `compositionOnly: false`
// compositionOnly: false,
// you need to set i18n resource including paths !
include: pathResolve('src/locales/**')
})
],
json: {
stringify: true
},
define: {
__APP_INFO__: JSON.stringify(__APP_INFO__)
},
resolve: {
alias: {
'@': pathResolve('src'),
types: pathResolve('types')
// dayjs: 'dayjs/esm'
}
}
}
}