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'
|
|
|
|
import type { MetaObject } from '@nuxt/meta'
|
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-07-28 11:48:17 +00:00
|
|
|
// Transpile @nuxt/meta
|
2021-07-28 12:00:39 +00:00
|
|
|
nuxt.options.build.transpile.push('@nuxt/meta', runtimeDir, '@vueuse/head')
|
2021-07-15 11:28:04 +00:00
|
|
|
nuxt.options.alias['@nuxt/meta'] = resolve(runtimeDir, 'index')
|
|
|
|
|
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
|
|
|
}
|
|
|
|
})
|