2021-09-27 12:49:36 +00:00
|
|
|
import { resolve } from 'pathe'
|
2023-03-10 08:01:21 +00:00
|
|
|
import { addComponent, addImportsSources, addPlugin, defineNuxtModule, tryResolveModule } from '@nuxt/kit'
|
2021-08-11 21:26:47 +00:00
|
|
|
import { distDir } from '../dirs'
|
2021-07-15 11:28:04 +00:00
|
|
|
|
2022-11-16 02:26:35 +00:00
|
|
|
const components = ['NoScript', 'Link', 'Base', 'Title', 'Meta', 'Style', 'Head', 'Html', 'Body']
|
2022-10-13 15:54:06 +00:00
|
|
|
|
2021-07-15 11:28:04 +00:00
|
|
|
export default defineNuxtModule({
|
2022-01-05 18:09:53 +00:00
|
|
|
meta: {
|
2023-03-10 08:01:21 +00:00
|
|
|
name: 'head'
|
2022-01-05 18:09:53 +00:00
|
|
|
},
|
2023-03-10 14:55:01 +00:00
|
|
|
async setup (options, nuxt) {
|
2023-03-10 08:01:21 +00:00
|
|
|
const runtimeDir = resolve(distDir, 'head/runtime')
|
2021-07-15 11:28:04 +00:00
|
|
|
|
2023-03-08 15:32:24 +00:00
|
|
|
// Transpile @unhead/vue
|
|
|
|
nuxt.options.build.transpile.push('@unhead/vue')
|
2021-08-11 20:28:38 +00:00
|
|
|
|
2023-03-10 08:01:21 +00:00
|
|
|
// TODO: remove alias in v3.4
|
|
|
|
nuxt.options.alias['#head'] = nuxt.options.alias['#app']
|
|
|
|
nuxt.hook('prepare:types', ({ tsConfig }) => {
|
|
|
|
tsConfig.compilerOptions = tsConfig.compilerOptions || {}
|
|
|
|
delete tsConfig.compilerOptions.paths['#head']
|
|
|
|
delete tsConfig.compilerOptions.paths['#head/*']
|
|
|
|
})
|
2021-07-15 11:28:04 +00:00
|
|
|
|
2022-10-13 15:54:06 +00:00
|
|
|
// Register components
|
|
|
|
const componentsPath = resolve(runtimeDir, 'components')
|
|
|
|
for (const componentName of components) {
|
|
|
|
addComponent({
|
|
|
|
name: componentName,
|
|
|
|
filePath: componentsPath,
|
|
|
|
export: componentName,
|
2023-03-06 11:33:40 +00:00
|
|
|
// built-in that we do not expect the user to override
|
|
|
|
priority: 10,
|
2022-10-13 15:54:06 +00:00
|
|
|
// kebab case version of these tags is not valid
|
|
|
|
kebabName: componentName
|
|
|
|
})
|
|
|
|
}
|
2023-03-10 08:01:21 +00:00
|
|
|
|
|
|
|
addImportsSources({
|
|
|
|
from: '@unhead/vue',
|
|
|
|
// hard-coded for now we so don't support auto-imports on the deprecated composables
|
|
|
|
imports: [
|
|
|
|
'injectHead',
|
|
|
|
'useHead',
|
|
|
|
'useSeoMeta',
|
|
|
|
'useHeadSafe',
|
|
|
|
'useServerHead',
|
|
|
|
'useServerSeoMeta',
|
|
|
|
'useServerHeadSafe'
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2023-03-08 15:32:24 +00:00
|
|
|
// Opt-out feature allowing dependencies using @vueuse/head to work
|
|
|
|
if (nuxt.options.experimental.polyfillVueUseHead) {
|
|
|
|
// backwards compatibility
|
2023-03-10 14:55:01 +00:00
|
|
|
nuxt.options.alias['@vueuse/head'] = await tryResolveModule('@unhead/vue') || '@unhead/vue'
|
2023-03-10 08:01:21 +00:00
|
|
|
addPlugin({ src: resolve(runtimeDir, 'plugins/vueuse-head-polyfill') })
|
2023-03-08 15:32:24 +00:00
|
|
|
}
|
2022-10-13 15:54:06 +00:00
|
|
|
|
2023-03-08 15:32:24 +00:00
|
|
|
// Add library-specific plugin
|
2023-03-10 08:01:21 +00:00
|
|
|
addPlugin({ src: resolve(runtimeDir, 'plugins/unhead') })
|
2021-07-15 11:28:04 +00:00
|
|
|
}
|
|
|
|
})
|