vben
authored
|
1
|
import type { UserConfig, ConfigEnv } from 'vite';
|
|
2
|
|
vben
authored
|
3
|
import { loadEnv } from 'vite';
|
vben
authored
|
4
|
import { resolve } from 'path';
|
vben
authored
|
5
|
|
vben
authored
|
6
|
import { generateModifyVars } from './build/config/themeConfig';
|
vben
authored
|
7
|
import { createProxy } from './build/vite/proxy';
|
vben
authored
|
8
|
import { wrapperEnv } from './build/utils';
|
vben
authored
|
9
|
import { createVitePlugins } from './build/vite/plugin';
|
vben
authored
|
10
|
import { OUTPUT_DIR } from './build/constant';
|
nebv
authored
|
11
|
|
|
12
13
14
|
function pathResolve(dir: string) {
return resolve(__dirname, '.', dir);
}
|
|
15
|
|
vben
authored
|
16
|
export default ({ command, mode }: ConfigEnv): UserConfig => {
|
vben
authored
|
17
18
|
const root = process.cwd();
|
vben
authored
|
19
|
const env = loadEnv(mode, root);
|
vben
authored
|
20
21
|
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
|
vben
authored
|
22
|
const viteEnv = wrapperEnv(env);
|
vben
authored
|
23
|
|
Vben
authored
|
24
|
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE, VITE_LEGACY } = viteEnv;
|
vben
authored
|
25
|
|
vben
authored
|
26
|
const isBuild = command === 'build';
|
vben
authored
|
27
|
|
vben
authored
|
28
|
return {
|
vben
authored
|
29
|
base: VITE_PUBLIC_PATH,
|
vben
authored
|
30
|
root,
|
vben
authored
|
31
32
33
34
35
36
37
|
resolve: {
alias: [
{
// /@/xxxx => src/xxx
find: /^\/@\//,
replacement: pathResolve('src') + '/',
},
|
Vben
authored
|
38
39
40
41
42
|
{
// /@/xxxx => src/xxx
find: /^\/#\//,
replacement: pathResolve('types') + '/',
},
|
vben
authored
|
43
44
|
],
},
|
vben
authored
|
45
46
|
server: {
port: VITE_PORT,
|
vben
authored
|
47
|
// Load proxy configuration from .env
|
vben
authored
|
48
49
50
51
52
|
proxy: createProxy(VITE_PROXY),
hmr: {
overlay: true,
},
},
|
vben
authored
|
53
|
|
vben
authored
|
54
|
build: {
|
Vben
authored
|
55
|
// minify: 'esbuild',
|
vben
authored
|
56
|
outDir: OUTPUT_DIR,
|
vben
authored
|
57
|
polyfillDynamicImport: VITE_LEGACY,
|
vben
authored
|
58
59
60
|
terserOptions: {
compress: {
keep_infinity: true,
|
vben
authored
|
61
|
// Used to delete console in production environment
|
vben
authored
|
62
63
|
drop_console: VITE_DROP_CONSOLE,
},
|
vben
authored
|
64
|
},
|
vben
authored
|
65
|
// Turning off brotliSize display can slightly reduce packaging time
|
vben
authored
|
66
|
brotliSize: false,
|
vben
authored
|
67
|
chunkSizeWarningLimit: 1200,
|
vben
authored
|
68
69
70
71
72
73
74
75
|
},
define: {
// setting vue-i18-next
// Suppress warning
__VUE_I18N_LEGACY_API__: false,
__VUE_I18N_FULL_INSTALL__: false,
__INTLIFY_PROD_DEVTOOLS__: false,
},
|
vben
authored
|
76
77
78
79
|
css: {
preprocessorOptions: {
less: {
modifyVars: {
|
vben
authored
|
80
|
// Used for global import to avoid the need to import each style file separately
|
vben
authored
|
81
|
// reference: Avoid repeated references
|
vben
authored
|
82
|
hack: `true; @import (reference) "${resolve('src/design/config.less')}";`,
|
vben
authored
|
83
|
...generateModifyVars(),
|
vben
authored
|
84
85
|
},
javascriptEnabled: true,
|
vben
authored
|
86
|
},
|
vben
authored
|
87
|
},
|
vben
authored
|
88
|
},
|
vben
authored
|
89
|
|
vben
authored
|
90
91
|
// The vite plugin used by the project. The quantity is large, so it is separately extracted and managed
plugins: createVitePlugins(viteEnv, isBuild),
|
vben
authored
|
92
|
|
vben
authored
|
93
|
optimizeDeps: {
|
vben
authored
|
94
|
// @iconify/iconify: The dependency is dynamically and virtually loaded by @purge-icons/generated, so it needs to be specified explicitly
|
Vben
authored
|
95
96
97
98
99
100
101
|
include: [
'@iconify/iconify',
'ant-design-vue/es/locale/zh_CN',
'moment/dist/locale/zh-cn',
'ant-design-vue/es/locale/en_US',
'moment/dist/locale/eu',
],
|
vben
authored
|
102
|
exclude: ['vue-demi'],
|
vben
authored
|
103
104
105
|
},
};
};
|