vben
authored
|
1
|
import type { UserConfig, ConfigEnv } from 'vite';
|
vben
authored
|
2
3
|
import pkg from './package.json';
import moment from 'moment';
|
vben
authored
|
4
|
import { loadEnv } from 'vite';
|
vben
authored
|
5
|
import { resolve } from 'path';
|
Vben
authored
|
6
|
import { generateModifyVars } from './build/generate/generateModifyVars';
|
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';
|
Vben
authored
|
11
|
|
Vben
authored
|
12
13
14
15
|
function pathResolve(dir: string) {
return resolve(process.cwd(), '.', dir);
}
|
Vben
authored
|
16
|
const { dependencies, devDependencies, name, version } = pkg;
|
Vben
authored
|
17
|
const __APP_INFO__ = {
|
Vben
authored
|
18
|
pkg: { dependencies, devDependencies, name, version },
|
Vben
authored
|
19
20
|
lastBuildTime: moment().format('YYYY-MM-DD HH:mm:ss'),
};
|
nebv
authored
|
21
|
|
vben
authored
|
22
|
export default ({ command, mode }: ConfigEnv): UserConfig => {
|
vben
authored
|
23
24
|
const root = process.cwd();
|
vben
authored
|
25
|
const env = loadEnv(mode, root);
|
vben
authored
|
26
27
|
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
|
vben
authored
|
28
|
const viteEnv = wrapperEnv(env);
|
vben
authored
|
29
|
|
Vben
authored
|
30
|
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE } = viteEnv;
|
vben
authored
|
31
|
|
vben
authored
|
32
|
const isBuild = command === 'build';
|
vben
authored
|
33
|
|
vben
authored
|
34
|
return {
|
vben
authored
|
35
|
base: VITE_PUBLIC_PATH,
|
vben
authored
|
36
|
root,
|
vben
authored
|
37
|
resolve: {
|
Vben
authored
|
38
|
alias: [
|
vben
authored
|
39
40
41
42
|
{
find: 'vue-i18n',
replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
},
|
Vben
authored
|
43
|
// /@/xxxx => src/xxxx
|
Vben
authored
|
44
45
46
47
|
{
find: /\/@\//,
replacement: pathResolve('src') + '/',
},
|
Vben
authored
|
48
|
// /#/xxxx => types/xxxx
|
Vben
authored
|
49
50
51
52
53
|
{
find: /\/#\//,
replacement: pathResolve('types') + '/',
},
],
|
vben
authored
|
54
|
},
|
vben
authored
|
55
|
server: {
|
|
56
57
|
// Listening on all local IPs
host: true,
|
vben
authored
|
58
|
port: VITE_PORT,
|
vben
authored
|
59
|
// Load proxy configuration from .env
|
vben
authored
|
60
61
62
|
proxy: createProxy(VITE_PROXY),
},
build: {
|
Vben
authored
|
63
|
target: 'es2015',
|
vben
authored
|
64
|
outDir: OUTPUT_DIR,
|
vben
authored
|
65
66
67
|
terserOptions: {
compress: {
keep_infinity: true,
|
vben
authored
|
68
|
// Used to delete console in production environment
|
vben
authored
|
69
70
|
drop_console: VITE_DROP_CONSOLE,
},
|
vben
authored
|
71
|
},
|
vben
authored
|
72
|
// Turning off brotliSize display can slightly reduce packaging time
|
vben
authored
|
73
|
brotliSize: false,
|
Vben
authored
|
74
|
chunkSizeWarningLimit: 2000,
|
vben
authored
|
75
76
|
},
define: {
|
vben
authored
|
77
78
79
|
// setting vue-i18-next
// Suppress warning
__INTLIFY_PROD_DEVTOOLS__: false,
|
Vben
authored
|
80
|
__APP_INFO__: JSON.stringify(__APP_INFO__),
|
vben
authored
|
81
|
},
|
vben
authored
|
82
|
|
vben
authored
|
83
84
85
|
css: {
preprocessorOptions: {
less: {
|
Vben
authored
|
86
|
modifyVars: generateModifyVars(),
|
vben
authored
|
87
|
javascriptEnabled: true,
|
vben
authored
|
88
|
},
|
vben
authored
|
89
|
},
|
vben
authored
|
90
|
},
|
vben
authored
|
91
|
|
vben
authored
|
92
93
|
// The vite plugin used by the project. The quantity is large, so it is separately extracted and managed
plugins: createVitePlugins(viteEnv, isBuild),
|
vben
authored
|
94
|
|
vben
authored
|
95
|
optimizeDeps: {
|
vben
authored
|
96
|
// @iconify/iconify: The dependency is dynamically and virtually loaded by @purge-icons/generated, so it needs to be specified explicitly
|
Vben
authored
|
97
98
99
100
101
102
103
|
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
|
104
|
exclude: ['vue-demi'],
|
vben
authored
|
105
106
107
|
},
};
};
|