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