Skip to content

Commit

Permalink
feat!: supports multiple default export types
Browse files Browse the repository at this point in the history
  • Loading branch information
markthree committed May 21, 2023
1 parent 7b8f22f commit 0e0548e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
8 changes: 4 additions & 4 deletions examples/vite/src/main.ts
Original file line number Diff line number Diff line change
@@ -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");
2 changes: 1 addition & 1 deletion examples/vite/src/modules/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ const router = createRouter({
history: createWebHistory()
})

export default (app: App) => app.use(router)
export default router
18 changes: 12 additions & 6 deletions src/shared/virtual.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { isVite2 } from './base'
import { isVite2 } from "./base";

/**
* 创建虚拟 Glob 引入
* @param glob
* @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 })`;
}

/**
Expand All @@ -17,15 +17,21 @@ 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 => {
Object.values(modules).forEach(module => {
if (typeof module.default === 'function') {
module.default(app)
}
if (Array.isArray(module.default)) {
app.use(...module.default)
}
app.use(module.default)
})
return app
}`
}`;
}

0 comments on commit 0e0548e

Please sign in to comment.