Nuxt/packages/nuxt/src/head/module.ts

31 lines
875 B
TypeScript
Raw Normal View History

import { resolve } from 'pathe'
import { addPlugin, addTemplate, defineNuxtModule } from '@nuxt/kit'
import { distDir } from '../dirs'
export default defineNuxtModule({
meta: {
name: 'meta'
},
setup (options, nuxt) {
const runtimeDir = nuxt.options.alias['#head'] || resolve(distDir, 'head/runtime')
// Transpile @nuxt/meta and @vueuse/head
2021-10-12 08:39:06 +00:00
nuxt.options.build.transpile.push('@vueuse/head')
// Add #head alias
nuxt.options.alias['#head'] = runtimeDir
// Add global meta configuration
addTemplate({
filename: 'meta.config.mjs',
getContents: () => 'export default ' + JSON.stringify({ globalMeta: nuxt.options.app.head })
})
// Add generic plugin
addPlugin({ src: resolve(runtimeDir, 'plugin') })
// Add library specific plugin
addPlugin({ src: resolve(runtimeDir, 'lib/vueuse-head.plugin') })
}
})