优化前端组件库拆包
This commit is contained in:
+27
-1
@@ -7,6 +7,32 @@ import Components from 'unplugin-vue-components/vite'
|
||||
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
||||
import { VantResolver } from '@vant/auto-import-resolver'
|
||||
|
||||
function elementPlusChunk(id: string) {
|
||||
const normalized = id.replace(/\\/g, '/')
|
||||
if (normalized.includes('@element-plus/icons-vue')) {
|
||||
return 'vendor-element-plus-icons'
|
||||
}
|
||||
const componentMatch = normalized.match(/element-plus\/es\/components\/([^/]+)/)
|
||||
if (!componentMatch) return undefined
|
||||
const component = componentMatch[1]
|
||||
if (
|
||||
[
|
||||
'table',
|
||||
'table-column',
|
||||
'form',
|
||||
'form-item',
|
||||
'select',
|
||||
'option',
|
||||
'input-number',
|
||||
'date-picker',
|
||||
'time-picker',
|
||||
].includes(component)
|
||||
) {
|
||||
return 'vendor-element-plus-data-entry'
|
||||
}
|
||||
return undefined
|
||||
}
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
vue(),
|
||||
@@ -49,7 +75,7 @@ export default defineConfig({
|
||||
manualChunks(id) {
|
||||
if (!id.includes('node_modules')) return
|
||||
if (id.includes('element-plus') || id.includes('@element-plus')) {
|
||||
return 'vendor-element-plus'
|
||||
return elementPlusChunk(id)
|
||||
}
|
||||
if (id.includes('vant') || id.includes('@vant')) {
|
||||
return 'vendor-vant'
|
||||
|
||||
Reference in New Issue
Block a user