2021-09-27 12:49:36 +00:00
|
|
|
import { resolve } from 'pathe'
|
2023-03-08 15:32:24 +00:00
|
|
|
import { addComponent, 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: {
|
|
|
|
name: 'meta'
|
|
|
|
},
|
2021-07-28 11:48:17 +00:00
|
|
|
setup (options, nuxt) {
|
2022-04-05 14:02:29 +00:00
|
|
|
const runtimeDir = nuxt.options.alias['#head'] || 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
|
|
|
|
2022-04-05 14:02:29 +00:00
|
|
|
// Add #head alias
|
|
|
|
nuxt.options.alias['#head'] = runtimeDir
|
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-08 15:32:24 +00:00
|
|
|
// Opt-out feature allowing dependencies using @vueuse/head to work
|
|
|
|
if (nuxt.options.experimental.polyfillVueUseHead) {
|
|
|
|
// backwards compatibility
|
|
|
|
nuxt.options.alias['@vueuse/head'] = tryResolveModule('@unhead/vue') || '@unhead/vue'
|
|
|
|
addPlugin({ src: resolve(runtimeDir, 'lib/vueuse-head-polyfill.plugin') })
|
|
|
|
}
|
2022-10-13 15:54:06 +00:00
|
|
|
|
2023-03-08 15:32:24 +00:00
|
|
|
// Add library-specific plugin
|
|
|
|
addPlugin({ src: resolve(runtimeDir, 'lib/unhead.plugin') })
|
2021-07-15 11:28:04 +00:00
|
|
|
}
|
|
|
|
})
|