feat(module): add support for vue using unplugin (#2416)

Co-authored-by: Benjamin Canac <canacb1@gmail.com>
This commit is contained in:
Daniel Roe
2024-10-25 16:15:26 +01:00
committed by GitHub
parent 50c6bf0092
commit d4a943e631
97 changed files with 18948 additions and 117 deletions

36
src/runtime/vue/stubs.ts Normal file
View File

@@ -0,0 +1,36 @@
import { ref } from 'vue'
import type { Ref, Plugin as VuePlugin } from 'vue'
import appConfig from '#build/app.config'
import type { NuxtApp } from '#app'
export { useHead } from '@unhead/vue'
export { useRoute, useRouter } from 'vue-router'
export const useAppConfig = () => appConfig
const state: Record<string, any> = {}
export const useState = <T>(key: string, init: () => T): Ref<T> => {
if (state[key]) {
return state[key] as Ref<T>
}
const value = ref(init())
state[key] = value
return value as Ref<T>
}
export function useNuxtApp() {
return {
isHydrating: true,
payload: { serverRendered: false }
}
}
export function defineNuxtPlugin(plugin: (nuxtApp: NuxtApp) => void) {
return {
install(app) {
plugin({ vueApp: app } as NuxtApp)
}
} satisfies VuePlugin
}