From 0e0548efbd23d5f320c30470deb37edd7ceab8d5 Mon Sep 17 00:00:00 2001 From: markthree <1801982702@qq.com> Date: Sun, 21 May 2023 13:30:33 +0800 Subject: [PATCH] feat!: supports multiple default export types --- examples/vite/src/main.ts | 8 ++++---- examples/vite/src/modules/router.ts | 2 +- src/shared/virtual.ts | 18 ++++++++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/examples/vite/src/main.ts b/examples/vite/src/main.ts index 1327900..8fb24d8 100644 --- a/examples/vite/src/main.ts +++ b/examples/vite/src/main.ts @@ -1,6 +1,6 @@ -import App from './App.vue' -import { createApp } from 'vue' +import App from "./App.vue"; +import { createApp } from "vue"; -const app = createApp(App) +const app = createApp(App); -app.mount('#app') +app.mount("#app"); diff --git a/examples/vite/src/modules/router.ts b/examples/vite/src/modules/router.ts index 2cd8b56..cfc384c 100644 --- a/examples/vite/src/modules/router.ts +++ b/examples/vite/src/modules/router.ts @@ -17,4 +17,4 @@ const router = createRouter({ history: createWebHistory() }) -export default (app: App) => app.use(router) +export default router diff --git a/src/shared/virtual.ts b/src/shared/virtual.ts index 8f0599f..20c5583 100644 --- a/src/shared/virtual.ts +++ b/src/shared/virtual.ts @@ -1,4 +1,4 @@ -import { isVite2 } from './base' +import { isVite2 } from "./base"; /** * 创建虚拟 Glob 引入 @@ -6,9 +6,9 @@ import { isVite2 } from './base' * @returns */ export async function createVirtualGlob(glob: string) { - return (await isVite2()) - ? `import.meta.globEager(${glob})` - : `import.meta.glob(${glob}, { eager: true })` + return (await isVite2()) + ? `import.meta.globEager(${glob})` + : `import.meta.glob(${glob}, { eager: true })`; } /** @@ -17,7 +17,7 @@ export async function createVirtualGlob(glob: string) { * @returns 虚拟模块 */ export async function createVirtualModule(glob: string) { - return `\n + return `\n export const modules = ${await createVirtualGlob(glob)} export const useModules = app => { @@ -25,7 +25,13 @@ export const useModules = app => { if (typeof module.default === 'function') { module.default(app) } + + if (Array.isArray(module.default)) { + app.use(...module.default) + } + + app.use(module.default) }) return app -}` +}`; }