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