2021-07-15 11:28:04 +00:00
|
|
|
import { resolve } from 'upath'
|
2021-07-28 11:48:17 +00:00
|
|
|
import { addPlugin, addTemplate, defineNuxtModule } from '@nuxt/kit'
|
2021-08-11 20:28:38 +00:00
|
|
|
import type { MetaObject } from './types'
|
2021-07-15 11:28:04 +00:00
|
|
|
|
|
|
|
export default defineNuxtModule({
|
|
|
|
name: 'meta',
|
2021-07-28 11:48:17 +00:00
|
|
|
defaults: {
|
|
|
|
charset: 'utf-8',
|
|
|
|
viewport: 'width=device-width, initial-scale=1'
|
|
|
|
},
|
|
|
|
setup (options, nuxt) {
|
2021-07-15 11:28:04 +00:00
|
|
|
const runtimeDir = resolve(__dirname, 'runtime')
|
|
|
|
|
2021-08-11 20:28:38 +00:00
|
|
|
// Transpile @nuxt/meta and @vueuse/head
|
|
|
|
nuxt.options.build.transpile.push(runtimeDir, '@vueuse/head')
|
|
|
|
|
|
|
|
// Add #meta alias
|
|
|
|
nuxt.options.alias['#meta'] = runtimeDir
|
2021-07-15 11:28:04 +00:00
|
|
|
|
2021-07-28 11:48:17 +00:00
|
|
|
// Global meta
|
|
|
|
const globalMeta: MetaObject = {
|
|
|
|
meta: [
|
|
|
|
{ charset: options.charset },
|
|
|
|
{ name: 'viewport', content: options.viewport }
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add global meta configuration
|
|
|
|
addTemplate({
|
|
|
|
filename: 'meta.config.mjs',
|
|
|
|
getContents: () => 'export default ' + JSON.stringify({ globalMeta })
|
2021-07-15 11:28:04 +00:00
|
|
|
})
|
2021-07-28 11:48:17 +00:00
|
|
|
|
|
|
|
// Add generic plugin
|
|
|
|
addPlugin({ src: resolve(runtimeDir, 'plugin') })
|
|
|
|
|
|
|
|
// Add library specific plugin
|
|
|
|
addPlugin({ src: resolve(runtimeDir, 'lib/vueuse-head.plugin') })
|
2021-07-15 11:28:04 +00:00
|
|
|
}
|
|
|
|
})
|