-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
155 lines (142 loc) · 4.33 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
import { resolve } from 'node:path'
import { cwd } from 'node:process'
import VueI18n from '@intlify/unplugin-vue-i18n/vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import UnoCSS from 'unocss/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { VueRouterAutoImports } from 'unplugin-vue-router'
import VueRouter from 'unplugin-vue-router/vite'
import { defineConfig, loadEnv } from 'vite'
import viteCompression from 'vite-plugin-compression2'
import VueDevTools from 'vite-plugin-vue-devtools'
import Layouts from 'vite-plugin-vue-layouts'
export default defineConfig(({ mode }) => {
// Load env variables.
const env = loadEnv(mode, cwd(), '')
// Manual chunks.
const chunks: string[] = ['axios', 'nprogress']
return {
base: env.VITE_APP_BASE_URL,
server: {
host: true,
port: 9865,
// Proxy request and socket.
// https://vitejs.dev/config/server-options.html#server-proxy
proxy: {
[env.VITE_PUBLIC_REQUEST_URL]: {
target: env.VITE_PUBLIC_REQUEST_URL_PROXY,
changeOrigin: true,
rewrite: (path: string) => path.replace(new RegExp(`^${env.VITE_PUBLIC_REQUEST_URL}`), ''),
},
},
},
preview: {
host: true,
port: 9865,
},
resolve: {
alias: {
// Alias for path.
// https://vitejs.dev/config/shared-options.html#resolve-alias
'@': resolve(__dirname, 'src'),
},
},
plugins: [
// Vue & Jsx plugin.
// https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue
// https://github.com/vitejs/vite-plugin-vue/tree/main/packages/plugin-vue-jsx
vue(),
vueJsx(),
// Vue layouts & pages plugin.
// https://github.com/JohnCampionJr/vite-plugin-vue-layouts
// https://github.com/posva/unplugin-vue-router
Layouts(),
VueRouter({
dts: 'typings/vue-router.d.ts',
}),
// UnoCSS plugin, you can see uno.config.ts.
UnoCSS(),
// Vue dev tools.
// https://github.com/webfansplz/vite-plugin-vue-devtools
VueDevTools(),
// Auto import api.
// https://github.com/unplugin/unplugin-auto-import
AutoImport({
imports: [
'vue',
VueRouterAutoImports,
{
// add any other imports you were relying on
'vue-router/auto': ['useLink'],
},
'vue-i18n',
'@vueuse/core',
'pinia',
],
dts: 'typings/auto-imports.d.ts',
dirs: [
'src/apis/**/*',
'src/composables/**/*',
'src/constants/**/*',
'src/stores/**/*',
'src/utils/**/*',
],
vueTemplate: true,
}),
// Auto registry components.
// https://github.com/antfu/unplugin-vue-components
Components({
extensions: ['vue'],
include: [/\.vue$/, /\.vue\?vue/],
dts: 'typings/components.d.ts',
}),
// Auto import i18n locales.
// https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n
VueI18n({
runtimeOnly: true,
compositionOnly: true,
fullInstall: true,
include: [resolve(__dirname, 'src/locales/**')],
}),
// Vite compression plugin.
// https://github.com/nonzzz/vite-plugin-compression
env.VITE_APP_GZIP === 'true' && viteCompression(),
],
// Optimize dependencies.
// https://vitejs.dev/config/#optimizedeps
optimizeDeps: {
include: [
'vue',
'vue-router',
'pinia',
'@vueuse/core',
'lodash-es',
],
},
// Vitest config.
// https://github.com/vitest-dev/vitest
test: {
include: ['tests/**/*'],
environment: 'jsdom',
},
// Vite build config.
// https://rollupjs.org/
build: {
outDir: 'dist',
assetsDir: 'assets',
rollupOptions: {
output: {
// https://rollupjs.org/configuration-options/#output-manualchunks
manualChunks: (id: string) => {
return chunks.find(chunk => id.includes(chunk))
},
chunkFileNames: 'assets/[name].[hash].js',
entryFileNames: 'assets/[name].[hash].js',
assetFileNames: 'assets/[name].[hash].[ext]',
},
},
},
}
})