fix: migrate import.meta.glob

This commit is contained in:
Anthony Fu 2022-07-14 03:19:15 +08:00
parent a56c80efa2
commit c316ca945c
2 changed files with 4 additions and 2 deletions

View File

@ -1,6 +1,7 @@
import { ViteSSG } from 'vite-ssg' import { ViteSSG } from 'vite-ssg'
import { setupLayouts } from 'virtual:generated-layouts' import { setupLayouts } from 'virtual:generated-layouts'
import App from './App.vue' import App from './App.vue'
import type { UserModule } from './types'
import generatedRoutes from '~pages' import generatedRoutes from '~pages'
import '@unocss/reset/tailwind.css' import '@unocss/reset/tailwind.css'
@ -15,6 +16,7 @@ export const createApp = ViteSSG(
{ routes, base: import.meta.env.BASE_URL }, { routes, base: import.meta.env.BASE_URL },
(ctx) => { (ctx) => {
// install all modules under `modules/` // install all modules under `modules/`
Object.values(import.meta.globEager('./modules/*.ts')).forEach(i => i.install?.(ctx)) Object.values(import.meta.glob<{ install: UserModule }>('./modules/*.ts', { eager: true }))
.forEach(i => i.install?.(ctx))
}, },
) )

View File

@ -7,7 +7,7 @@ import { type UserModule } from '~/types'
// Don't need this? Try vitesse-lite: https://github.com/antfu/vitesse-lite // Don't need this? Try vitesse-lite: https://github.com/antfu/vitesse-lite
const messages = Object.fromEntries( const messages = Object.fromEntries(
Object.entries( Object.entries(
import.meta.globEager('../../locales/*.y(a)?ml')) import.meta.glob<{ default: any }>('../../locales/*.y(a)?ml', { eager: true }))
.map(([key, value]) => { .map(([key, value]) => {
const yaml = key.endsWith('.yaml') const yaml = key.endsWith('.yaml')
return [key.slice(14, yaml ? -5 : -4), value.default] return [key.slice(14, yaml ? -5 : -4), value.default]