Commit 664035328f8e2a3cdce7af4935b395523317e90e
1 parent
d2bdc566
wip: suppoer vite2 -- dynamic import
Showing
8 changed files
with
20 additions
and
37 deletions
build/vite/plugin/importContext.ts deleted
100644 → 0
1 | -import dynamicImport from 'vite-plugin-import-context'; | |
2 | -import type { ViteEnv } from '../../utils'; | |
3 | -import type { Plugin } from 'vite'; | |
4 | - | |
5 | -export function configDynamicImport(env: ViteEnv) { | |
6 | - const { VITE_DYNAMIC_IMPORT } = env; | |
7 | - const dynamicImportPlugin: Plugin = dynamicImport({ | |
8 | - include: ['**/*.ts'], | |
9 | - autoImportRoute: VITE_DYNAMIC_IMPORT, | |
10 | - }); | |
11 | - return dynamicImportPlugin; | |
12 | -} |
build/vite/plugin/index.ts
... | ... | @@ -10,7 +10,6 @@ import { ViteEnv, isReportMode } from '../../utils'; |
10 | 10 | import { configHtmlPlugin } from './html'; |
11 | 11 | import { configPwaConfig } from './pwa'; |
12 | 12 | import { configMockPlugin } from './mock'; |
13 | -import { configDynamicImport } from './importContext'; | |
14 | 13 | import { configGzipPlugin } from './gzip'; |
15 | 14 | |
16 | 15 | // gen vite plugins |
... | ... | @@ -26,9 +25,6 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean, mode: stri |
26 | 25 | // vite-plugin-mock |
27 | 26 | vitePlugins.push(configMockPlugin(viteEnv, isBuild)); |
28 | 27 | |
29 | - // vite-plugin-import-context | |
30 | - vitePlugins.push(configDynamicImport(viteEnv)); | |
31 | - | |
32 | 28 | // vite-plugin-purge-icons |
33 | 29 | vitePlugins.push(PurgeIcons()); |
34 | 30 | ... | ... |
package.json
... | ... | @@ -100,7 +100,6 @@ |
100 | 100 | "typescript": "^4.1.3", |
101 | 101 | "vite": "^2.0.0-beta.19", |
102 | 102 | "vite-plugin-html": "^2.0.0-beta.5", |
103 | - "vite-plugin-import-context": "^1.0.0-rc.1", | |
104 | 103 | "vite-plugin-mock": "^2.0.0-beta.1", |
105 | 104 | "vite-plugin-purge-icons": "^0.5.0", |
106 | 105 | "vite-plugin-pwa": "^0.3.3", | ... | ... |
src/hooks/web/useI18n.ts
... | ... | @@ -22,9 +22,9 @@ export function useI18n(namespace?: string) { |
22 | 22 | |
23 | 23 | const { t, ...methods } = i18n.global; |
24 | 24 | |
25 | - const tFn = function (...arg: Parameters<typeof t>) { | |
26 | - if (!arg[0]) return ''; | |
27 | - return t(getKey(arg[0]), ...(arg as Parameters<typeof t>)); | |
25 | + const tFn: typeof t = (key: string, ...arg: any) => { | |
26 | + if (!key) return ''; | |
27 | + return t(getKey(key), ...(arg as Parameters<typeof t>)); | |
28 | 28 | }; |
29 | 29 | return { |
30 | 30 | ...methods, | ... | ... |
src/router/helper/routeHelper.ts
... | ... | @@ -9,17 +9,10 @@ export type LayoutMapKey = 'LAYOUT'; |
9 | 9 | |
10 | 10 | const LayoutMap = new Map<LayoutMapKey, () => Promise<typeof import('*.vue')>>(); |
11 | 11 | |
12 | +const dynamicViewsModules = import.meta.glob('../../views/**/*.{vue,tsx}'); | |
13 | + | |
12 | 14 | // 动态引入 |
13 | 15 | function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) { |
14 | - // TODO Because xlsx does not support vite2.0 temporarily. So filter the excel example first | |
15 | - // regexp: /^(?!.*\/demo\/excel).*\.(tsx?|vue)$/, | |
16 | - const dynamicViewsModules = importContext({ | |
17 | - dir: '/@/views', | |
18 | - deep: true, | |
19 | - regexp: /\.(tsx?|vue)$/, | |
20 | - dynamicImport: true, | |
21 | - dynamicEnabled: 'autoImportRoute', | |
22 | - }); | |
23 | 16 | if (!routes) return; |
24 | 17 | routes.forEach((item) => { |
25 | 18 | const { component, name } = item; |
... | ... | @@ -33,15 +26,23 @@ function asyncImportRoute(routes: AppRouteRecordRaw[] | undefined) { |
33 | 26 | }); |
34 | 27 | } |
35 | 28 | |
36 | -function dynamicImport(dynamicViewsModules: DynamicImportContextResult, component: string) { | |
37 | - const keys = dynamicViewsModules.keys(); | |
29 | +function dynamicImport( | |
30 | + dynamicViewsModules: Record< | |
31 | + string, | |
32 | + () => Promise<{ | |
33 | + [key: string]: any; | |
34 | + }> | |
35 | + >, | |
36 | + component: string | |
37 | +) { | |
38 | + const keys = Object.keys(dynamicViewsModules); | |
38 | 39 | const matchKeys = keys.filter((key) => { |
39 | - const k = key.substr(1); | |
40 | - return k.startsWith(component) || k.startsWith(`/${component}`); | |
40 | + const k = key.replace('../../views', ''); | |
41 | + return k.startsWith(`${component}`) || k.startsWith(`/${component}`); | |
41 | 42 | }); |
42 | 43 | if (matchKeys?.length === 1) { |
43 | 44 | const matchKey = matchKeys[0]; |
44 | - return dynamicViewsModules(matchKey); | |
45 | + return dynamicViewsModules[matchKey]; | |
45 | 46 | } |
46 | 47 | if (matchKeys?.length > 1) { |
47 | 48 | warn( | ... | ... |
src/settings/projectSetting.ts
... | ... | @@ -12,7 +12,7 @@ const setting: ProjectConfig = { |
12 | 12 | showSettingButton: true, |
13 | 13 | |
14 | 14 | // Permission mode |
15 | - permissionMode: PermissionModeEnum.ROLE, | |
15 | + permissionMode: PermissionModeEnum.BACK, | |
16 | 16 | |
17 | 17 | // Permission-related cache is stored in sessionStorage or localStorage |
18 | 18 | permissionCacheType: CacheTypeEnum.LOCAL, | ... | ... |
src/setup/App.ts
... | ... | @@ -39,7 +39,6 @@ export function useThemeMode(mode: ThemeModeEnum) { |
39 | 39 | export function initAppConfigStore() { |
40 | 40 | let projCfg: ProjectConfig = getLocal(PROJ_CFG_KEY) as ProjectConfig; |
41 | 41 | projCfg = deepMerge(projectSetting, projCfg || {}); |
42 | - | |
43 | 42 | try { |
44 | 43 | const { |
45 | 44 | colorWeak, | ... | ... |
tsconfig.json
... | ... | @@ -16,7 +16,7 @@ |
16 | 16 | "noUnusedParameters": true, |
17 | 17 | "experimentalDecorators": true, |
18 | 18 | "lib": ["dom", "esnext"], |
19 | - "types": ["vite/client", "vite-plugin-import-context/client"], | |
19 | + "types": ["vite/client"], | |
20 | 20 | "incremental": true, |
21 | 21 | "skipLibCheck": true, |
22 | 22 | "paths": { | ... | ... |