@origen-ui/admin-cli 1.1.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +41 -9
- package/package.json +26 -2
- package/templates/current/clean/.node-version +1 -0
- package/templates/current/clean/CHANGELOG.md +125 -0
- package/templates/current/clean/README.md +2 -1
- package/templates/current/clean/component-catalog.json +58 -17
- package/templates/current/clean/e2e/admin-shell.spec.ts +6 -0
- package/templates/current/clean/e2e/demo-shell.spec.ts +94 -50
- package/templates/current/clean/package.json +39 -25
- package/templates/current/clean/playwright.config.ts +1 -0
- package/templates/current/clean/playwright.demo.config.ts +1 -1
- package/templates/current/clean/pnpm-workspace.yaml +18 -0
- package/templates/current/clean/scaffold.lock.json +2 -2
- package/templates/current/clean/scripts/check-admin-scaffold.mjs +5 -1
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/clean/scripts/clean-overlay/src/main.ts +23 -14
- package/templates/current/clean/scripts/clean-overlay/src/router/componentCache.ts +12 -0
- package/templates/current/clean/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
- package/templates/current/clean/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/clean/scripts/clean-overlay/src/router/paths.ts +21 -0
- package/templates/current/clean/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
- package/templates/current/clean/scripts/demo-api.ts +88 -12
- package/templates/current/clean/scripts/generate-api.ts +87 -3
- package/templates/current/clean/scripts/remove-examples.mjs +4 -4
- package/templates/current/clean/scripts/vite-build-policy.spec.ts +1 -0
- package/templates/current/clean/src/api/generated/data-contracts.ts +2 -5
- package/templates/current/clean/src/api/generated/http-client.ts +28 -26
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +5 -8
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -4
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +2 -5
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +8 -10
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +11 -12
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +8 -10
- package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +8 -10
- package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +3 -6
- package/templates/current/clean/src/app/errorMessage.spec.ts +76 -0
- package/templates/current/clean/src/app/errorMessage.ts +53 -0
- package/templates/current/clean/src/app/menu-host.spec.ts +77 -0
- package/templates/current/clean/src/app/menu.spec.ts +39 -0
- package/templates/current/clean/src/app/menu.ts +48 -12
- package/templates/current/clean/src/app/runtimeConfig.ts +1 -1
- package/templates/current/clean/src/demo-api.spec.ts +314 -3
- package/templates/current/clean/src/features/auth/pages/Login.vue +9 -2
- package/templates/current/clean/src/features/auth/store/auth.ts +6 -19
- package/templates/current/clean/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/clean/src/features/system/access/api/admin-repository.ts +2 -6
- package/templates/current/clean/src/features/system/access/api/rbac.ts +19 -9
- package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
- package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
- package/templates/current/clean/src/features/workspace/pages/Profile.vue +1 -1
- package/templates/current/clean/src/layouts/AdminLayout.vue +3 -0
- package/templates/current/clean/src/layouts/TopBar.vue +37 -6
- package/templates/current/clean/src/layouts/topBarMenuSearch.spec.ts +24 -1
- package/templates/current/clean/src/layouts/topBarMenuSearch.ts +10 -0
- package/templates/current/clean/src/locales/en-US.json +30 -3
- package/templates/current/clean/src/locales/en-US.runtime.ts +2 -0
- package/templates/current/clean/src/locales/index.ts +39 -26
- package/templates/current/clean/src/locales/zh-CN.json +30 -3
- package/templates/current/clean/src/locales/zh-CN.runtime.ts +2 -0
- package/templates/current/clean/src/locales/zh-TW.json +30 -3
- package/templates/current/clean/src/locales/zh-TW.runtime.ts +2 -0
- package/templates/current/clean/src/main.ts +23 -14
- package/templates/current/clean/src/router/bootstrap.ts +10 -16
- package/templates/current/clean/src/router/componentCache.ts +12 -0
- package/templates/current/clean/src/router/componentRegistry.ts +2 -13
- package/templates/current/clean/src/router/dynamicMenuRefresh.spec.ts +101 -0
- package/templates/current/clean/src/router/dynamicMenuRefresh.ts +24 -0
- package/templates/current/clean/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/clean/src/router/dynamicRoutes.ts +14 -3
- package/templates/current/clean/src/router/paths.spec.ts +50 -0
- package/templates/current/clean/src/router/paths.ts +21 -0
- package/templates/current/clean/src/router/queryEncryption.spec.ts +10 -1
- package/templates/current/clean/src/router/routeQuery.spec.ts +2 -1
- package/templates/current/clean/src/router/routeQuery.ts +4 -1
- package/templates/current/clean/src/router/staticRoutes.ts +6 -6
- package/templates/current/clean/src/templates/og-table.ts +2 -4
- package/templates/current/clean/tsconfig.json +0 -1
- package/templates/current/clean/vite.build-policy.ts +55 -8
- package/templates/current/clean/vite.config.ts +30 -0
- package/templates/current/examples/.node-version +1 -0
- package/templates/current/examples/CHANGELOG.md +125 -0
- package/templates/current/examples/README.md +2 -1
- package/templates/current/examples/component-catalog.json +58 -17
- package/templates/current/examples/e2e/admin-shell.spec.ts +6 -0
- package/templates/current/examples/e2e/demo-shell.spec.ts +94 -50
- package/templates/current/examples/package.json +39 -25
- package/templates/current/examples/playwright.config.ts +1 -0
- package/templates/current/examples/playwright.demo.config.ts +1 -1
- package/templates/current/examples/pnpm-workspace.yaml +18 -0
- package/templates/current/examples/scaffold.lock.json +2 -2
- package/templates/current/examples/scripts/check-admin-scaffold.mjs +5 -1
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/examples/scripts/clean-overlay/src/main.ts +23 -14
- package/templates/current/examples/scripts/clean-overlay/src/router/componentCache.ts +12 -0
- package/templates/current/examples/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
- package/templates/current/examples/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/examples/scripts/clean-overlay/src/router/paths.ts +21 -0
- package/templates/current/examples/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
- package/templates/current/examples/scripts/demo-api.ts +88 -12
- package/templates/current/examples/scripts/generate-api.ts +87 -3
- package/templates/current/examples/scripts/remove-examples.mjs +4 -4
- package/templates/current/examples/scripts/vite-build-policy.spec.ts +1 -0
- package/templates/current/examples/src/api/generated/data-contracts.ts +2 -5
- package/templates/current/examples/src/api/generated/http-client.ts +28 -26
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +5 -8
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +1 -4
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +2 -5
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +8 -10
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +11 -12
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +8 -10
- package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +8 -10
- package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +3 -6
- package/templates/current/examples/src/app/errorMessage.spec.ts +76 -0
- package/templates/current/examples/src/app/errorMessage.ts +53 -0
- package/templates/current/examples/src/app/menu-host.spec.ts +77 -0
- package/templates/current/examples/src/app/menu.spec.ts +39 -0
- package/templates/current/examples/src/app/menu.ts +48 -12
- package/templates/current/examples/src/app/runtimeConfig.ts +1 -1
- package/templates/current/examples/src/demo-api.spec.ts +314 -3
- package/templates/current/examples/src/features/auth/pages/Login.vue +9 -2
- package/templates/current/examples/src/features/auth/store/auth.ts +6 -19
- package/templates/current/examples/src/features/errors/pages/Forbidden.vue +2 -1
- package/templates/current/examples/src/features/errors/pages/NotFound.vue +2 -1
- package/templates/current/examples/src/features/errors/pages/ServerError.vue +2 -1
- package/templates/current/examples/src/features/feature-composables.spec.ts +11 -1
- package/templates/current/examples/src/features/system/access/api/admin-repository.ts +2 -6
- package/templates/current/examples/src/features/system/access/api/rbac.ts +19 -9
- package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
- package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
- package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +115 -28
- package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +162 -66
- package/templates/current/examples/src/features/system/menus/menuDraft.spec.ts +204 -0
- package/templates/current/examples/src/features/system/menus/menuDraft.ts +116 -0
- package/templates/current/examples/src/features/system/menus/menuTreePrecheck.spec.ts +268 -0
- package/templates/current/examples/src/features/system/menus/menuTreePrecheck.ts +317 -0
- package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +1 -0
- package/templates/current/examples/src/features/workspace/pages/Profile.vue +1 -1
- package/templates/current/examples/src/layouts/AdminLayout.vue +3 -0
- package/templates/current/examples/src/layouts/TopBar.vue +37 -6
- package/templates/current/examples/src/layouts/topBarMenuSearch.spec.ts +24 -1
- package/templates/current/examples/src/layouts/topBarMenuSearch.ts +10 -0
- package/templates/current/examples/src/locales/en-US.json +30 -3
- package/templates/current/examples/src/locales/en-US.runtime.ts +2 -0
- package/templates/current/examples/src/locales/index.ts +39 -26
- package/templates/current/examples/src/locales/zh-CN.json +30 -3
- package/templates/current/examples/src/locales/zh-CN.runtime.ts +2 -0
- package/templates/current/examples/src/locales/zh-TW.json +30 -3
- package/templates/current/examples/src/locales/zh-TW.runtime.ts +2 -0
- package/templates/current/examples/src/main.ts +24 -22
- package/templates/current/examples/src/router/bootstrap.ts +10 -16
- package/templates/current/examples/src/router/componentCache.ts +18 -0
- package/templates/current/examples/src/router/componentRegistry.ts +1 -18
- package/templates/current/examples/src/router/dynamicMenuRefresh.spec.ts +101 -0
- package/templates/current/examples/src/router/dynamicMenuRefresh.ts +24 -0
- package/templates/current/examples/src/router/dynamicRoutes.spec.ts +20 -2
- package/templates/current/examples/src/router/dynamicRoutes.ts +14 -3
- package/templates/current/examples/src/router/paths.spec.ts +50 -0
- package/templates/current/examples/src/router/paths.ts +21 -0
- package/templates/current/examples/src/router/queryEncryption.spec.ts +10 -1
- package/templates/current/examples/src/router/routeQuery.spec.ts +2 -1
- package/templates/current/examples/src/router/routeQuery.ts +4 -1
- package/templates/current/examples/src/router/staticRoutes.ts +3 -3
- package/templates/current/examples/src/templates/og-table.ts +2 -4
- package/templates/current/examples/tsconfig.json +0 -1
- package/templates/current/examples/vite.build-policy.ts +55 -8
- package/templates/current/examples/vite.config.ts +30 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* componentKey → 页面组件 name 映射,用于生成 KeepAlive 缓存名单。
|
|
3
|
+
*
|
|
4
|
+
* KeepAlive 的 `:include` 匹配的是页面组件渲染后的 name(SFC `defineOptions({ name })`),
|
|
5
|
+
* 因此这里的值必须与各页面组件的 defineOptions name 完全一致,否则缓存失效。
|
|
6
|
+
* 修改组件 name 时必须同步更新此表,并保持 dynamicRoutes.spec.ts 断言一致。
|
|
7
|
+
*/
|
|
8
|
+
export const componentCacheNames: Readonly<Record<string, string>> = {
|
|
9
|
+
'dashboard': 'DashboardPage',
|
|
10
|
+
'profile': 'ProfilePage',
|
|
11
|
+
'user-list': 'UserListPage',
|
|
12
|
+
'role-list': 'RoleListPage',
|
|
13
|
+
'menu-list': 'MenuListPage',
|
|
14
|
+
'audit-list': 'AuditListPage',
|
|
15
|
+
'empty': 'EmptyPage',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const fallbackComponentKey = 'empty'
|
|
@@ -30,24 +30,7 @@ function withComponentStyles(key: string, loadComponent: ComponentLoader): Compo
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
* componentKey → 页面组件 name 映射,用于生成 KeepAlive 缓存名单。
|
|
35
|
-
*
|
|
36
|
-
* KeepAlive 的 `:include` 匹配的是页面组件渲染后的 name(SFC `defineOptions({ name })`),
|
|
37
|
-
* 因此这里的值必须与各页面组件的 defineOptions name 完全一致,否则缓存失效。
|
|
38
|
-
* 修改组件 name 时必须同步更新此表,并保持 dynamicRoutes.spec.ts 断言一致。
|
|
39
|
-
*/
|
|
40
|
-
export const componentCacheNames: Readonly<Record<string, string>> = {
|
|
41
|
-
'dashboard': 'DashboardPage',
|
|
42
|
-
'profile': 'ProfilePage',
|
|
43
|
-
'user-list': 'UserListPage',
|
|
44
|
-
'role-list': 'RoleListPage',
|
|
45
|
-
'menu-list': 'MenuListPage',
|
|
46
|
-
'audit-list': 'AuditListPage',
|
|
47
|
-
'empty': 'EmptyPage',
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export const fallbackComponentKey = 'empty'
|
|
33
|
+
export { componentCacheNames, fallbackComponentKey } from './componentCache'
|
|
51
34
|
|
|
52
35
|
export const componentRegistry: Map<string, ComponentLoader> = new Map([
|
|
53
36
|
[
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import type { BackendMenuNode } from '../app/menuTypes'
|
|
2
|
+
import { createRouterAdapter } from '@origen-ui/router'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
import { defineComponent } from 'vue'
|
|
5
|
+
import { createMemoryHistory } from 'vue-router'
|
|
6
|
+
import { replaceDynamicMenusWithAccessibleFallback } from './dynamicMenuRefresh'
|
|
7
|
+
import { routeTransformer } from './dynamicRoutes'
|
|
8
|
+
|
|
9
|
+
const View = defineComponent({ template: '<div />' })
|
|
10
|
+
|
|
11
|
+
const staticRoutes = [
|
|
12
|
+
{ name: 'login', path: '/login', component: View, meta: { adapter: { public: true, menu: { hidden: true } } } },
|
|
13
|
+
{ name: '404', path: '/404', component: View, meta: { adapter: { public: true, menu: { hidden: true } } } },
|
|
14
|
+
{ name: '500', path: '/500', component: View, meta: { adapter: { public: true, menu: { hidden: true } } } },
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
function createAdaptersWithMenus(menus: readonly BackendMenuNode[]) {
|
|
18
|
+
let current = menus
|
|
19
|
+
const adapter = createRouterAdapter<BackendMenuNode>({
|
|
20
|
+
history: createMemoryHistory(),
|
|
21
|
+
staticRoutes,
|
|
22
|
+
dynamic: {
|
|
23
|
+
load: async () => current,
|
|
24
|
+
transform: routeTransformer,
|
|
25
|
+
resolveComponent: () => () => Promise.resolve(View),
|
|
26
|
+
},
|
|
27
|
+
fallbacks: { notFound: { name: '404' }, error: { name: '500' } },
|
|
28
|
+
})
|
|
29
|
+
return {
|
|
30
|
+
adapter,
|
|
31
|
+
setMenus(next: readonly BackendMenuNode[]) {
|
|
32
|
+
current = [...next]
|
|
33
|
+
},
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
describe('replaceDynamicMenusWithAccessibleFallback', () => {
|
|
38
|
+
it('falls back to the first reachable menu entry when home is revoked', async () => {
|
|
39
|
+
const { adapter, setMenus } = createAdaptersWithMenus([
|
|
40
|
+
{ code: 'dashboard', path: '/dashboard', title: 'Dashboard' },
|
|
41
|
+
{ code: 'reports', path: '/reports', title: 'Reports' },
|
|
42
|
+
])
|
|
43
|
+
await adapter.router.push('/reports')
|
|
44
|
+
await adapter.router.isReady()
|
|
45
|
+
expect(adapter.router.currentRoute.value.path).toBe('/reports')
|
|
46
|
+
|
|
47
|
+
// 主页与当前页同时被裁撤:回落到刷新后菜单里首个真实可达入口。
|
|
48
|
+
setMenus([{ code: 'audit', path: '/audit', title: 'Audit' }])
|
|
49
|
+
await replaceDynamicMenusWithAccessibleFallback(adapter)
|
|
50
|
+
|
|
51
|
+
expect(adapter.router.currentRoute.value.path).toBe('/audit')
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('lands on home when the current route disappears but home remains', async () => {
|
|
55
|
+
const { adapter, setMenus } = createAdaptersWithMenus([
|
|
56
|
+
{ code: 'dashboard', path: '/dashboard', title: 'Dashboard' },
|
|
57
|
+
{ code: 'reports', path: '/reports', title: 'Reports' },
|
|
58
|
+
])
|
|
59
|
+
await adapter.router.push('/reports')
|
|
60
|
+
await adapter.router.isReady()
|
|
61
|
+
|
|
62
|
+
setMenus([{ code: 'dashboard', path: '/dashboard', title: 'Dashboard' }])
|
|
63
|
+
await replaceDynamicMenusWithAccessibleFallback(adapter)
|
|
64
|
+
|
|
65
|
+
expect(adapter.router.currentRoute.value.path).toBe('/dashboard')
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
it('skips a directory whose redirect target was revoked and lands on a real entry', async () => {
|
|
69
|
+
const { adapter, setMenus } = createAdaptersWithMenus([
|
|
70
|
+
{ code: 'system', path: '/system', title: 'System', redirect: '/dashboard' },
|
|
71
|
+
{ code: 'reports', path: '/reports', title: 'Reports' },
|
|
72
|
+
])
|
|
73
|
+
await adapter.router.push('/reports')
|
|
74
|
+
await adapter.router.isReady()
|
|
75
|
+
|
|
76
|
+
// 主页被裁撤后,首个菜单项(目录)的 redirect 仍指向 /dashboard——
|
|
77
|
+
// 可达性校验必须跳过它,否则会再次落回 404。
|
|
78
|
+
setMenus([
|
|
79
|
+
{ code: 'system', path: '/system', title: 'System', redirect: '/dashboard' },
|
|
80
|
+
{ code: 'audit', path: '/audit', title: 'Audit' },
|
|
81
|
+
])
|
|
82
|
+
await replaceDynamicMenusWithAccessibleFallback(adapter)
|
|
83
|
+
|
|
84
|
+
expect(adapter.router.currentRoute.value.path).toBe('/audit')
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('does not redirect when the session is already on the not-found page', async () => {
|
|
88
|
+
const { adapter, setMenus } = createAdaptersWithMenus([
|
|
89
|
+
{ code: 'dashboard', path: '/dashboard', title: 'Dashboard' },
|
|
90
|
+
{ code: 'reports', path: '/reports', title: 'Reports' },
|
|
91
|
+
])
|
|
92
|
+
await adapter.router.push('/reports')
|
|
93
|
+
await adapter.router.isReady()
|
|
94
|
+
await adapter.router.push('/404')
|
|
95
|
+
|
|
96
|
+
setMenus([{ code: 'audit', path: '/audit', title: 'Audit' }])
|
|
97
|
+
await replaceDynamicMenusWithAccessibleFallback(adapter)
|
|
98
|
+
|
|
99
|
+
expect(adapter.router.currentRoute.value.name).toBe('404')
|
|
100
|
+
})
|
|
101
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { RouterAdapter } from '@origen-ui/router'
|
|
2
|
+
import type { RouteLocationRaw } from 'vue-router'
|
|
3
|
+
import type { BackendMenuNode } from '../app/menuTypes'
|
|
4
|
+
import { isUnmatchedRoute } from '@origen-ui/router'
|
|
5
|
+
import { firstMenuTarget, HOME_ROUTE, NOT_FOUND_ROUTE_NAME } from './paths'
|
|
6
|
+
|
|
7
|
+
function isReachableTarget(routing: RouterAdapter<BackendMenuNode>, to: RouteLocationRaw): boolean {
|
|
8
|
+
const resolved = routing.router.resolve(to)
|
|
9
|
+
return resolved.matched.length > 0 && !isUnmatchedRoute(resolved)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 替换动态菜单并在当前路由失效时回落:优先主页;主页已被裁撤时取
|
|
14
|
+
* 刷新后菜单树的首个真实可达入口,而不是把会话滞留在 404 页。
|
|
15
|
+
*/
|
|
16
|
+
export async function replaceDynamicMenusWithAccessibleFallback(
|
|
17
|
+
routing: RouterAdapter<BackendMenuNode>,
|
|
18
|
+
): Promise<void> {
|
|
19
|
+
const wasOnNotFound = routing.router.currentRoute.value.name === NOT_FOUND_ROUTE_NAME
|
|
20
|
+
await routing.replaceDynamicRoutes(undefined, { fallback: HOME_ROUTE })
|
|
21
|
+
if (wasOnNotFound || routing.router.currentRoute.value.name !== NOT_FOUND_ROUTE_NAME) return
|
|
22
|
+
const fallback = firstMenuTarget(routing.menu.value, (to) => isReachableTarget(routing, to))
|
|
23
|
+
if (fallback) await routing.router.replace(fallback)
|
|
24
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { componentCacheNames } from './
|
|
3
|
-
import { componentRegistry
|
|
2
|
+
import { componentCacheNames } from './componentCache'
|
|
3
|
+
import { componentRegistry } from './componentRegistry'
|
|
4
|
+
import { routeTransformer } from './dynamicRoutes'
|
|
4
5
|
import { staticRoutes } from './staticRoutes'
|
|
5
6
|
|
|
6
7
|
describe('dynamic component registry', () => {
|
|
@@ -83,6 +84,23 @@ describe('dynamic component registry', () => {
|
|
|
83
84
|
children: [{ path: 'users', children: [{ path: 'roles' }] }],
|
|
84
85
|
})
|
|
85
86
|
})
|
|
87
|
+
|
|
88
|
+
it('rejects flat parentPath entries whose parent route does not exist', () => {
|
|
89
|
+
expect(() =>
|
|
90
|
+
routeTransformer([
|
|
91
|
+
{ code: 'orphan', path: 'orphan', parentPath: '/missing', title: 'Orphan' },
|
|
92
|
+
]),
|
|
93
|
+
).toThrow('Unresolved dynamic route parent path: /missing')
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
it('rejects duplicate route codes with an explicit error', () => {
|
|
97
|
+
expect(() =>
|
|
98
|
+
routeTransformer([
|
|
99
|
+
{ code: 'dup', path: '/first', title: 'First' },
|
|
100
|
+
{ code: 'dup', path: '/second', title: 'Second' },
|
|
101
|
+
]),
|
|
102
|
+
).toThrow('Duplicate dynamic route code: dup')
|
|
103
|
+
})
|
|
86
104
|
})
|
|
87
105
|
|
|
88
106
|
describe('keep-alive cache names', () => {
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { RouteSourceNode } from '@origen-ui/router'
|
|
2
2
|
import type { BackendMenuNode } from '../app/menuTypes'
|
|
3
|
-
import { componentCacheNames, fallbackComponentKey } from './
|
|
4
|
-
|
|
5
|
-
export { componentRegistry } from './componentRegistry'
|
|
3
|
+
import { componentCacheNames, fallbackComponentKey } from './componentCache'
|
|
6
4
|
|
|
7
5
|
function routeName(source: BackendMenuNode, used: Set<string>): string {
|
|
8
6
|
const base = `dyn-${source.code.replace(/[^\w-]+/g, '-').replace(/^-|-$/g, '') || 'route'}`
|
|
@@ -128,6 +126,8 @@ function buildTree(nodes: readonly BackendMenuNode[]): readonly BackendMenuNode[
|
|
|
128
126
|
])
|
|
129
127
|
candidates.delete(item)
|
|
130
128
|
if (candidates.size > 1) throw new Error(`Ambiguous dynamic route parent path: ${parentPath}`)
|
|
129
|
+
if (candidates.size === 0)
|
|
130
|
+
throw new Error(`Unresolved dynamic route parent path: ${parentPath}`)
|
|
131
131
|
}
|
|
132
132
|
|
|
133
133
|
for (const item of entries) {
|
|
@@ -144,7 +144,18 @@ function buildTree(nodes: readonly BackendMenuNode[]): readonly BackendMenuNode[
|
|
|
144
144
|
return roots.map(materialize)
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
+
function assertUniqueCodes(nodes: readonly BackendMenuNode[], seen = new Set<string>()): void {
|
|
148
|
+
for (const node of nodes) {
|
|
149
|
+
if (seen.has(node.code)) throw new Error(`Duplicate dynamic route code: ${node.code}`)
|
|
150
|
+
seen.add(node.code)
|
|
151
|
+
assertUniqueCodes(node.children ?? [], seen)
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
147
155
|
export function routeTransformer(sources: readonly BackendMenuNode[]): readonly RouteSourceNode[] {
|
|
156
|
+
// buildTree 按 code 去重会静默丢弃后到的重复节点,连同其子树一起消失;
|
|
157
|
+
// 在此显式失败,给出可定位的数据错误。
|
|
158
|
+
assertUniqueCodes(sources)
|
|
148
159
|
const usedNames = new Set<string>()
|
|
149
160
|
const tree = buildTree(sources)
|
|
150
161
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { RouteMenuItem } from '@origen-ui/router'
|
|
2
|
+
import { describe, expect, it } from 'vitest'
|
|
3
|
+
import { firstMenuTarget, HOME_ROUTE, NOT_FOUND_ROUTE_NAME } from './paths'
|
|
4
|
+
import { staticRoutes } from './staticRoutes'
|
|
5
|
+
|
|
6
|
+
describe('router paths', () => {
|
|
7
|
+
it('keeps the root static redirect aligned with HOME_ROUTE', () => {
|
|
8
|
+
const root = staticRoutes.find((route) => route.name === 'root')
|
|
9
|
+
expect(root?.redirect).toBe(HOME_ROUTE)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
it('pins the not-found fallback to the static 404 route', () => {
|
|
13
|
+
expect(staticRoutes.some((route) => route.name === NOT_FOUND_ROUTE_NAME)).toBe(true)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
it('resolves the first navigable menu target depth-first', () => {
|
|
17
|
+
const items = [
|
|
18
|
+
{ id: 'locked', label: 'Locked', children: [] },
|
|
19
|
+
{
|
|
20
|
+
id: 'section',
|
|
21
|
+
label: 'Section',
|
|
22
|
+
to: { name: 'section' },
|
|
23
|
+
children: [{ id: 'inner', label: 'Inner', to: { name: 'inner' }, children: [] }],
|
|
24
|
+
},
|
|
25
|
+
] as readonly RouteMenuItem[]
|
|
26
|
+
|
|
27
|
+
expect(firstMenuTarget(items)).toEqual({ name: 'section' })
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('returns undefined when no menu item is navigable', () => {
|
|
31
|
+
const items = [{ id: 'empty', label: 'Empty', children: [] }] as readonly RouteMenuItem[]
|
|
32
|
+
|
|
33
|
+
expect(firstMenuTarget(items)).toBeUndefined()
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('skips entries rejected by the reachability predicate', () => {
|
|
37
|
+
const items = [
|
|
38
|
+
{ id: 'gone', label: 'Gone', to: { path: '/gone' }, children: [] },
|
|
39
|
+
{ id: 'live', label: 'Live', to: { name: 'live' }, children: [] },
|
|
40
|
+
] as readonly RouteMenuItem[]
|
|
41
|
+
|
|
42
|
+
expect(
|
|
43
|
+
firstMenuTarget(items, (to) => {
|
|
44
|
+
const path = typeof to === 'string' ? to : to.path
|
|
45
|
+
return path !== '/gone'
|
|
46
|
+
}),
|
|
47
|
+
).toEqual({ name: 'live' })
|
|
48
|
+
expect(firstMenuTarget(items, () => false)).toBeUndefined()
|
|
49
|
+
})
|
|
50
|
+
})
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RouteMenuItem } from '@origen-ui/router'
|
|
2
|
+
import type { RouteLocationRaw } from 'vue-router'
|
|
3
|
+
|
|
4
|
+
/** 授权后的默认首页路由;与 staticRoutes 根路由 redirect 由 paths.spec 钉住一致。 */
|
|
5
|
+
export const HOME_ROUTE = '/dashboard'
|
|
6
|
+
|
|
7
|
+
/** staticRoutes 中 404 兜底页的路由名。 */
|
|
8
|
+
export const NOT_FOUND_ROUTE_NAME = '404'
|
|
9
|
+
|
|
10
|
+
/** 深度优先取菜单树中首个可导航入口;isReachable 用于剔除重定向到已裁撤路由的目录项。 */
|
|
11
|
+
export function firstMenuTarget(
|
|
12
|
+
items: readonly RouteMenuItem[],
|
|
13
|
+
isReachable: (to: RouteLocationRaw) => boolean = () => true,
|
|
14
|
+
): RouteLocationRaw | undefined {
|
|
15
|
+
for (const item of items) {
|
|
16
|
+
if (item.to && isReachable(item.to)) return item.to
|
|
17
|
+
const child = firstMenuTarget(item.children, isReachable)
|
|
18
|
+
if (child) return child
|
|
19
|
+
}
|
|
20
|
+
return undefined
|
|
21
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { RouteRecordRaw } from 'vue-router'
|
|
2
2
|
import { gcm } from '@noble/ciphers/aes.js'
|
|
3
|
-
import { createRouterAdapter } from '@origen-ui/router'
|
|
3
|
+
import { createRouterAdapter, getRouteQueryString } from '@origen-ui/router'
|
|
4
4
|
import { describe, expect, it } from 'vitest'
|
|
5
5
|
import { defineComponent } from 'vue'
|
|
6
6
|
import { createMemoryHistory } from 'vue-router'
|
|
@@ -70,6 +70,15 @@ describe('route query encryption', () => {
|
|
|
70
70
|
expect(codec.parseQuery(`${encoded}&_q=${encodeURIComponent('v2.invalid.ciphertext')}`)).toEqual({})
|
|
71
71
|
})
|
|
72
72
|
|
|
73
|
+
it('normalizes encrypted single-value arrays without choosing duplicate values', () => {
|
|
74
|
+
const codec = createRouteQueryEncryption({ enabled: true, key })!
|
|
75
|
+
const single = codec.parseQuery(codec.stringifyQuery({ redirect: ['/dashboard'] }))
|
|
76
|
+
const duplicate = codec.parseQuery(codec.stringifyQuery({ redirect: ['/a', '/b'] }))
|
|
77
|
+
|
|
78
|
+
expect(getRouteQueryString(single.redirect)).toBe('/dashboard')
|
|
79
|
+
expect(getRouteQueryString(duplicate.redirect)).toBeUndefined()
|
|
80
|
+
})
|
|
81
|
+
|
|
73
82
|
it('rejects authenticated JSON values that are not a route query shape', () => {
|
|
74
83
|
const codec = createRouteQueryEncryption({ enabled: true, key })!
|
|
75
84
|
|
|
@@ -5,7 +5,8 @@ describe('route query helpers', () => {
|
|
|
5
5
|
it('accepts only supported status values', () => {
|
|
6
6
|
expect(routeStatus('active')).toBe('active')
|
|
7
7
|
expect(routeStatus('suspended')).toBe('suspended')
|
|
8
|
-
expect(routeStatus(['suspended'])).
|
|
8
|
+
expect(routeStatus(['suspended'])).toBe('suspended')
|
|
9
|
+
expect(routeStatus(['active', 'suspended'])).toBeUndefined()
|
|
9
10
|
expect(routeStatus('unknown')).toBeUndefined()
|
|
10
11
|
})
|
|
11
12
|
})
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { getRouteQueryString } from '@origen-ui/router'
|
|
2
|
+
|
|
1
3
|
export function routeStatus(value: unknown): 'active' | 'suspended' | undefined {
|
|
2
|
-
|
|
4
|
+
const normalized = getRouteQueryString(value)
|
|
5
|
+
return normalized === 'active' || normalized === 'suspended' ? normalized : undefined
|
|
3
6
|
}
|
|
@@ -46,18 +46,18 @@ export const staticRoutes: RouteRecordRaw[] = [
|
|
|
46
46
|
path: '/403',
|
|
47
47
|
name: '403',
|
|
48
48
|
component: Forbidden,
|
|
49
|
-
meta: { adapter: { titleKey: 'errors.forbidden', ...hiddenPublic } },
|
|
49
|
+
meta: { adapter: { titleKey: 'errors.forbidden.title', ...hiddenPublic } },
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
path: '/404',
|
|
53
53
|
name: '404',
|
|
54
54
|
component: NotFound,
|
|
55
|
-
meta: { adapter: { titleKey: 'errors.notFound', ...hiddenPublic } },
|
|
55
|
+
meta: { adapter: { titleKey: 'errors.notFound.title', ...hiddenPublic } },
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
path: '/500',
|
|
59
59
|
name: '500',
|
|
60
60
|
component: ServerError,
|
|
61
|
-
meta: { adapter: { titleKey: 'errors.
|
|
61
|
+
meta: { adapter: { titleKey: 'errors.serverError.title', ...hiddenPublic } },
|
|
62
62
|
},
|
|
63
63
|
]
|
|
@@ -9,12 +9,10 @@ import type {
|
|
|
9
9
|
TableRowKey,
|
|
10
10
|
} from '@origen-ui/table'
|
|
11
11
|
import type { AdminMessageKey } from '../locales'
|
|
12
|
-
import {
|
|
12
|
+
import { translateAdminMessage } from '../locales'
|
|
13
13
|
|
|
14
14
|
function tableText(key: AdminMessageKey): string {
|
|
15
|
-
|
|
16
|
-
{ t: (key: AdminMessageKey) => string } | undefined
|
|
17
|
-
return global ? global.t(key) : key
|
|
15
|
+
return translateAdminMessage(key)
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
function withLocalizedLabel<T extends object>(
|
|
@@ -7,10 +7,7 @@ const packageBuildDirectories = new Set(['dist', 'es', 'esm', 'lib', 'src'])
|
|
|
7
7
|
const MAX_INITIAL_VENDOR_CHUNK_BYTES = 300 * 1024
|
|
8
8
|
const MAX_ASYNC_VENDOR_CHUNK_BYTES = 400 * 1024
|
|
9
9
|
|
|
10
|
-
type AdminCodeSplitting = Exclude<
|
|
11
|
-
NonNullable<Rolldown.OutputOptions['codeSplitting']>,
|
|
12
|
-
boolean
|
|
13
|
-
>
|
|
10
|
+
type AdminCodeSplitting = Exclude<NonNullable<Rolldown.OutputOptions['codeSplitting']>, boolean>
|
|
14
11
|
|
|
15
12
|
function chunkName(value: string): string {
|
|
16
13
|
return value
|
|
@@ -20,7 +17,12 @@ function chunkName(value: string): string {
|
|
|
20
17
|
.toLowerCase()
|
|
21
18
|
}
|
|
22
19
|
|
|
23
|
-
|
|
20
|
+
interface ModuleLocation {
|
|
21
|
+
name: string
|
|
22
|
+
path: string[]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function dependencyPath(normalized: string): ModuleLocation | undefined {
|
|
24
26
|
const marker = '/node_modules/'
|
|
25
27
|
const nodeModulesIndex = normalized.lastIndexOf(marker)
|
|
26
28
|
if (nodeModulesIndex < 0) return undefined
|
|
@@ -35,7 +37,7 @@ function dependencyPath(normalized: string): { name: string, path: string[] } |
|
|
|
35
37
|
}
|
|
36
38
|
}
|
|
37
39
|
|
|
38
|
-
function workspacePackagePath(normalized: string):
|
|
40
|
+
function workspacePackagePath(normalized: string): ModuleLocation | undefined {
|
|
39
41
|
const match = normalized.match(/\/packages\/([^/]+)\/(?:dist|src)\/(.+)$/)
|
|
40
42
|
if (!match) return undefined
|
|
41
43
|
return { name: `og-${match[1]}`, path: match[2].split('/') }
|
|
@@ -62,7 +64,9 @@ function vendorLocation(id: string) {
|
|
|
62
64
|
|
|
63
65
|
function matchesPackageFamily(id: string, names: readonly string[]): boolean {
|
|
64
66
|
const name = vendorLocation(id)?.name
|
|
65
|
-
return Boolean(
|
|
67
|
+
return Boolean(
|
|
68
|
+
name && names.some((candidate) => name === candidate || name.startsWith(`${candidate}/`)),
|
|
69
|
+
)
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
function matchesPackageEntry(id: string, packageName: string, entry: string): boolean {
|
|
@@ -70,6 +74,24 @@ function matchesPackageEntry(id: string, packageName: string, entry: string): bo
|
|
|
70
74
|
return location?.name === packageName && location.path[0] === entry
|
|
71
75
|
}
|
|
72
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Element Plus table internals are extracted from the table-suite chunk they
|
|
79
|
+
* would otherwise co-locate with. The og-table family chunk itself must stay
|
|
80
|
+
* a single chunk — splitting it creates circular chunk-evaluation edges
|
|
81
|
+
* before Element Plus initializes (see the vendor-table-suite note) — but the
|
|
82
|
+
* Element Plus table code it pulls in is a leaf dependency and splits safely.
|
|
83
|
+
* This separation is what keeps the family chunk under the single-chunk
|
|
84
|
+
* budget instead of carrying the whole Element Plus table surface.
|
|
85
|
+
*
|
|
86
|
+
* `moduleLocation` strips the build directory, so published `es/components/…`
|
|
87
|
+
* paths start at `components`.
|
|
88
|
+
*/
|
|
89
|
+
function matchesElementPlusTableModule(id: string, component: 'table' | 'table-v2'): boolean {
|
|
90
|
+
const location = vendorLocation(id)
|
|
91
|
+
if (!location || location.name !== 'element-plus') return false
|
|
92
|
+
return location.path[0] === 'components' && location.path[1] === component
|
|
93
|
+
}
|
|
94
|
+
|
|
73
95
|
function dynamicPackageGroup(
|
|
74
96
|
id: string,
|
|
75
97
|
directory?: 'components' | 'languages' | 'locale',
|
|
@@ -77,7 +99,8 @@ function dynamicPackageGroup(
|
|
|
77
99
|
const location = vendorLocation(id)
|
|
78
100
|
if (!location || location.name === 'element-plus') return undefined
|
|
79
101
|
if (directory && location.path[0] !== directory) return undefined
|
|
80
|
-
const suffix =
|
|
102
|
+
const suffix =
|
|
103
|
+
directory === 'components' ? '-components' : directory ? `-${chunkName(directory)}` : ''
|
|
81
104
|
return `vendor-${chunkName(location.name)}${suffix}`
|
|
82
105
|
}
|
|
83
106
|
|
|
@@ -104,6 +127,14 @@ export function createAdminCodeSplitting(): AdminCodeSplitting {
|
|
|
104
127
|
test: (id) => matchesPackageFamily(id, ['@floating-ui', '@sxzz/popperjs-es']),
|
|
105
128
|
priority: 85,
|
|
106
129
|
},
|
|
130
|
+
{
|
|
131
|
+
// async-validator is a leaf dependency shared by the form and table
|
|
132
|
+
// surfaces. Keeping it outside the table family avoids making the
|
|
133
|
+
// deliberately single-chunk family carry validation internals.
|
|
134
|
+
name: 'vendor-async-validator',
|
|
135
|
+
test: (id) => matchesPackageFamily(id, ['async-validator']),
|
|
136
|
+
priority: 83,
|
|
137
|
+
},
|
|
107
138
|
{
|
|
108
139
|
name: 'vendor-table-suite',
|
|
109
140
|
test: (id) =>
|
|
@@ -122,6 +153,22 @@ export function createAdminCodeSplitting(): AdminCodeSplitting {
|
|
|
122
153
|
// circular chunk-evaluation edge before Element Plus initializes.
|
|
123
154
|
priority: 80,
|
|
124
155
|
},
|
|
156
|
+
{
|
|
157
|
+
// Leaf dependency of the table-suite family: extracted so the family
|
|
158
|
+
// chunk stays under the single-chunk budget. The priority must sit
|
|
159
|
+
// ABOVE vendor-table-suite — Rolldown lets a higher-priority chunk
|
|
160
|
+
// pull lower-priority-grouped dependencies into itself, which is
|
|
161
|
+
// exactly how the Element Plus table internals ended up inside the
|
|
162
|
+
// family chunk — but still below the positioning/vueuse families.
|
|
163
|
+
name: 'vendor-element-table-v2',
|
|
164
|
+
test: (id) => matchesElementPlusTableModule(id, 'table-v2'),
|
|
165
|
+
priority: 82,
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: 'vendor-element-table',
|
|
169
|
+
test: (id) => matchesElementPlusTableModule(id, 'table'),
|
|
170
|
+
priority: 81,
|
|
171
|
+
},
|
|
125
172
|
{
|
|
126
173
|
name: 'vendor-initial',
|
|
127
174
|
test: (id) => Boolean(vendorLocation(id)),
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { existsSync, readdirSync } from 'node:fs'
|
|
2
|
+
import { dirname, join } from 'node:path'
|
|
1
3
|
import process from 'node:process'
|
|
2
4
|
import { fileURLToPath } from 'node:url'
|
|
3
5
|
import vue from '@vitejs/plugin-vue'
|
|
@@ -9,6 +11,17 @@ import { defineConfig } from 'vitest/config'
|
|
|
9
11
|
// with the application source as ./vite.build-policy.ts.
|
|
10
12
|
import { createAdminBuildOptions, createAdminBuildPlugins } from './vite.build-policy.js'
|
|
11
13
|
|
|
14
|
+
const elementPlusPackageRoot = dirname(dirname(fileURLToPath(import.meta.resolve('element-plus'))))
|
|
15
|
+
const elementPlusStyleIncludes = readdirSync(join(elementPlusPackageRoot, 'es/components'), {
|
|
16
|
+
withFileTypes: true,
|
|
17
|
+
})
|
|
18
|
+
.filter(
|
|
19
|
+
(entry) =>
|
|
20
|
+
entry.isDirectory() &&
|
|
21
|
+
existsSync(join(elementPlusPackageRoot, 'es/components', entry.name, 'style/index.mjs')),
|
|
22
|
+
)
|
|
23
|
+
.map((entry) => `element-plus/es/components/${entry.name}/style/index`)
|
|
24
|
+
|
|
12
25
|
export default defineConfig(({ command, mode }) => {
|
|
13
26
|
const loadedEnv = loadEnv(mode, process.cwd(), '')
|
|
14
27
|
const apiTarget = loadedEnv.VITE_API_TARGET || 'http://127.0.0.1:8080'
|
|
@@ -17,6 +30,23 @@ export default defineConfig(({ command, mode }) => {
|
|
|
17
30
|
return {
|
|
18
31
|
plugins: [vue(), vueJsx(), ...createAdminBuildPlugins(), ElementPlus({ useSource: true })],
|
|
19
32
|
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
|
|
33
|
+
optimizeDeps: {
|
|
34
|
+
// Element Plus injects these entries only after lazy SFCs transform.
|
|
35
|
+
// Pre-bundle them up front and keep the dependency set fixed for route loads.
|
|
36
|
+
noDiscovery: true,
|
|
37
|
+
include: [
|
|
38
|
+
'@element-plus/icons-vue',
|
|
39
|
+
'@vueuse/core',
|
|
40
|
+
'axios',
|
|
41
|
+
'element-plus',
|
|
42
|
+
'pinia',
|
|
43
|
+
'sortablejs',
|
|
44
|
+
'vue',
|
|
45
|
+
'vue-i18n',
|
|
46
|
+
'vue-router',
|
|
47
|
+
...elementPlusStyleIncludes,
|
|
48
|
+
],
|
|
49
|
+
},
|
|
20
50
|
oxc: {
|
|
21
51
|
jsx: { runtime: 'automatic', importSource: 'vue' },
|
|
22
52
|
...(command === 'build' && !isDebugBuild ? { dropConsole: true, dropDebugger: true } : {}),
|