refactor(nuxt): remove vue-meta for head support (#9638)

This commit is contained in:
Harlan Wilton 2022-12-12 21:07:31 +11:00 committed by GitHub
parent 1a6186f3a8
commit 4cb7e425a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 2 additions and 59 deletions

View File

@ -23,7 +23,6 @@ export default defineBuildConfig({
externals: [
'@vue/reactivity',
'@vue/shared',
'@vueuse/head',
'vue-meta'
'@vueuse/head'
]
})

View File

@ -84,8 +84,7 @@
"devDependencies": {
"@types/fs-extra": "^9.0.13",
"@types/hash-sum": "^1.0.0",
"unbuild": "latest",
"vue-meta": "next"
"unbuild": "latest"
},
"engines": {
"node": "^14.16.0 || ^16.10.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"

View File

@ -1,43 +0,0 @@
import { createApp } from 'vue'
import { createMetaManager } from 'vue-meta'
import type { MetaObject } from '..'
import { defineNuxtPlugin } from '#app'
// @ts-expect-error untyped
import { appHead } from '#build/nuxt.config.mjs'
export default defineNuxtPlugin((nuxtApp) => {
// @ts-expect-error missing resolver
const manager = createMetaManager(process.server)
manager.addMeta(appHead)
nuxtApp.vueApp.use(manager)
nuxtApp._useHead = (meta: MetaObject) => manager.addMeta(meta)
if (process.client) {
const teleportTarget = document.createElement('div')
teleportTarget.id = 'head-target'
document.body.appendChild(teleportTarget)
createApp({ render: () => manager.render({}) }).mount('#head-target')
}
if (process.server) {
nuxtApp.ssrContext!.renderMeta = async () => {
// @ts-ignore
const { renderMetaToString } = await import('vue-meta/ssr')
nuxtApp.ssrContext!.teleports = nuxtApp.ssrContext!.teleports || {}
await renderMetaToString(nuxtApp.app, nuxtApp.ssrContext)
return {
htmlAttrs: nuxtApp.ssrContext!.teleports.htmlAttrs || '',
headAttrs: nuxtApp.ssrContext!.teleports.headAttrs || '',
bodyAttrs: nuxtApp.ssrContext!.teleports.bodyAttrs || '',
headTags: nuxtApp.ssrContext!.teleports.head || '',
bodyScriptsPrepend: nuxtApp.ssrContext!.teleports['body-prepend'] || '',
bodyScripts: nuxtApp.ssrContext!.teleports.body || ''
}
}
}
})

View File

@ -19,7 +19,6 @@ export default defineBuildConfig({
],
externals: [
// Type imports
'vue-meta',
'vue-router',
'vue-bundle-renderer',
'@unhead/schema',

View File

@ -455,7 +455,6 @@ importers:
vue: 3.2.45
vue-bundle-renderer: ^1.0.0
vue-devtools-stub: ^0.1.0
vue-meta: next
vue-router: ^4.1.6
dependencies:
'@nuxt/devalue': 2.0.0
@ -506,7 +505,6 @@ importers:
'@types/fs-extra': 9.0.13
'@types/hash-sum': 1.0.0
unbuild: 1.0.2
vue-meta: 3.0.0-alpha.2_vue@3.2.45
packages/schema:
specifiers:
@ -8980,15 +8978,6 @@ packages:
webpack: 5.75.0
dev: false
/vue-meta/3.0.0-alpha.2_vue@3.2.45:
resolution: {integrity: sha512-mLDB/vGjn2Q58IFKs5Dtp/STWZ0sEbkdM67u+YXuMreK5EjNHnqhcylQb+xn50pwxCdQD98nGgJlEXkh16Hqug==}
peerDependencies:
'@vue/server-renderer': ^3.0.6
vue: ^3.0.0
dependencies:
vue: 3.2.45
dev: true
/vue-router/4.1.6_vue@3.2.45:
resolution: {integrity: sha512-DYWYwsG6xNPmLq/FmZn8Ip+qrhFEzA14EI12MsMgVxvHFDYvlr4NXpVF5hrRH1wVcDP8fGi5F4rxuJSl8/r+EQ==}
peerDependencies: