2021-09-27 12:49:36 +00:00
|
|
|
import { resolve } from 'pathe'
|
2021-10-06 12:37:45 +00:00
|
|
|
import { addPlugin, addTemplate, defineNuxtModule, isNuxt3 } from '@nuxt/kit'
|
|
|
|
import defu from 'defu'
|
2021-08-11 21:26:47 +00:00
|
|
|
import { distDir } from '../dirs'
|
2021-10-02 23:00:21 +00:00
|
|
|
import type { MetaObject } from './runtime'
|
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
|
|
|
defaults: {
|
|
|
|
charset: 'utf-8',
|
|
|
|
viewport: 'width=device-width, initial-scale=1'
|
|
|
|
},
|
|
|
|
setup (options, nuxt) {
|
2021-10-06 12:37:45 +00:00
|
|
|
const runtimeDir = nuxt.options.alias['#meta'] || resolve(distDir, 'meta/runtime')
|
2021-07-15 11:28:04 +00:00
|
|
|
|
2021-08-11 20:28:38 +00:00
|
|
|
// Transpile @nuxt/meta and @vueuse/head
|
2021-10-12 08:39:06 +00:00
|
|
|
nuxt.options.build.transpile.push('@vueuse/head')
|
2021-08-11 20:28:38 +00:00
|
|
|
|
|
|
|
// 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
|
2021-10-06 12:37:45 +00:00
|
|
|
const globalMeta: MetaObject = defu(nuxt.options.meta, {
|
2021-07-28 11:48:17 +00:00
|
|
|
meta: [
|
|
|
|
{ charset: options.charset },
|
|
|
|
{ name: 'viewport', content: options.viewport }
|
|
|
|
]
|
2021-10-06 12:37:45 +00:00
|
|
|
})
|
2021-07-28 11:48:17 +00:00
|
|
|
|
|
|
|
// Add global meta configuration
|
|
|
|
addTemplate({
|
|
|
|
filename: 'meta.config.mjs',
|
2021-10-06 12:37:45 +00:00
|
|
|
getContents: () => 'export default ' + JSON.stringify({ globalMeta, mixinKey: isNuxt3() ? 'created' : 'setup' })
|
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
|
|
|
}
|
|
|
|
})
|