fix(nuxt): resolve @unhead/vue in template code (#23858)

This commit is contained in:
Daniel Roe 2023-10-22 09:39:56 +02:00 committed by GitHub
parent 06e6140953
commit d6c196afad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -48,9 +48,10 @@ export default defineNuxtModule({
}) })
// Opt-out feature allowing dependencies using @vueuse/head to work // Opt-out feature allowing dependencies using @vueuse/head to work
const unheadVue = await tryResolveModule('@unhead/vue', nuxt.options.modulesDir) || '@unhead/vue'
if (nuxt.options.experimental.polyfillVueUseHead) { if (nuxt.options.experimental.polyfillVueUseHead) {
// backwards compatibility // backwards compatibility
nuxt.options.alias['@vueuse/head'] = await tryResolveModule('@unhead/vue', nuxt.options.modulesDir) || '@unhead/vue' nuxt.options.alias['@vueuse/head'] = unheadVue
addPlugin({ src: resolve(runtimeDir, 'plugins/vueuse-head-polyfill') }) addPlugin({ src: resolve(runtimeDir, 'plugins/vueuse-head-polyfill') })
} }
@ -60,7 +61,7 @@ export default defineNuxtModule({
if (!nuxt.options.experimental.headNext) { if (!nuxt.options.experimental.headNext) {
return 'export default []' return 'export default []'
} }
return `import { CapoPlugin } from '@unhead/vue'; return `import { CapoPlugin } from ${JSON.stringify(unheadVue)};
export default process.server ? [CapoPlugin({ track: true })] : [];` export default process.server ? [CapoPlugin({ track: true })] : [];`
} }
}) })