Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
perf(nuxt)!: use component loader to add meta components (#8167)
Browse files Browse the repository at this point in the history
Co-authored-by: Daniel Roe <daniel@roe.dev>
  • Loading branch information
harlan-zw and danielroe committed Oct 13, 2022
1 parent 6ad0f3f commit 577573f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
20 changes: 17 additions & 3 deletions packages/nuxt/src/head/module.ts
@@ -1,7 +1,9 @@
import { resolve } from 'pathe'
import { addPlugin, defineNuxtModule } from '@nuxt/kit'
import { addComponent, addPlugin, defineNuxtModule } from '@nuxt/kit'
import { distDir } from '../dirs'

const components = ['Script', 'NoScript', 'Link', 'Base', 'Title', 'Meta', 'Style', 'Head', 'Html', 'Body']

export default defineNuxtModule({
meta: {
name: 'meta'
Expand All @@ -15,8 +17,20 @@ export default defineNuxtModule({
// Add #head alias
nuxt.options.alias['#head'] = runtimeDir

// Add generic plugin
addPlugin({ src: resolve(runtimeDir, 'plugin') })
// Register components
const componentsPath = resolve(runtimeDir, 'components')
for (const componentName of components) {
addComponent({
name: componentName,
filePath: componentsPath,
export: componentName,
// kebab case version of these tags is not valid
kebabName: componentName
})
}

// Add mixin plugin
addPlugin({ src: resolve(runtimeDir, 'mixin-plugin') })

// Add library specific plugin
addPlugin({ src: resolve(runtimeDir, 'lib/vueuse-head.plugin') })
Expand Down
@@ -1,13 +1,7 @@
import { getCurrentInstance } from 'vue'
import * as Components from './components'
import { useHead } from './composables'
import { defineNuxtPlugin, useNuxtApp } from '#app'

type MetaComponents = typeof Components
declare module '@vue/runtime-core' {
export interface GlobalComponents extends MetaComponents {}
}

const metaMixin = {
created () {
const instance = getCurrentInstance()
Expand All @@ -27,9 +21,4 @@ const metaMixin = {

export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.mixin(metaMixin)

for (const name in Components) {
// eslint-disable-next-line import/namespace
nuxtApp.vueApp.component(name, (Components as any)[name])
}
})

0 comments on commit 577573f

Please sign in to comment.