-
Notifications
You must be signed in to change notification settings - Fork 2
/
vite.config.js
78 lines (70 loc) · 2.22 KB
/
vite.config.js
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
import { fileURLToPath } from 'node:url'
import { readFileSync } from 'node:fs'
import { dirname, resolve } from 'node:path'
import { defineConfig, isCSSRequest, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import { reduce } from 'lodash-es'
const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)
const vendors = reduce({
'vue-vendor': ['vue', 'vue-router', 'pinia'],
'antd-vendor': ['ant-design-vue', '@ant-design/icons-vue'],
'utils-vendor': ['dayjs', 'lodash-es'],
'common-vendor': ['axios', 'vue-i18n', 'js-cookie', 'nprogress']
}, (result, modules, key) => {
const needVendors = modules.map((name) => {
return { name: name, vendor: key }
})
return [...result, ...needVendors]
}, [])
function manualChunks (id) {
if (id.includes('/node_modules/') && !isCSSRequest(id)) {
const result = vendors.find((item) => {
return id.includes(`/node_modules/${item.name}/`)
})
return result ? result.vendor : undefined
}
return undefined
}
function readPackageFile () {
const urlPath = new URL('./package.json', import.meta.url)
const file = readFileSync(urlPath, 'utf-8')
return JSON.parse(file)
}
export default defineConfig((config) => {
const env = loadEnv(config.mode, __dirname, ['VITE_', 'ENV_'])
const { version } = readPackageFile()
const APP_ENV = env['VITE_VUE_APP_ENV'] || 'production'
const isProd = APP_ENV === 'production'
return {
base: './',
plugins: [
vue(),
vueJsx()
],
build: {
rollupOptions: {
output: {
manualChunks: manualChunks
}
}
},
css: {
preprocessorOptions: {
scss: {
additionalData: '@import \'@/css/mixin.scss\';@import \'@/css/theme.scss\';'
}
}
},
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
'@site-pro': resolve(__dirname, 'packages')
}
},
define: {
'__SITE_VERSION__': `'${version}'`
}
}
})