mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): deduplicate global components before registration (#20743)
This commit is contained in:
parent
8cca5cc9d8
commit
53fef72031
@ -36,13 +36,20 @@ export default defineNuxtPlugin({
|
|||||||
export const componentsPluginTemplate: NuxtPluginTemplate<ComponentsTemplateContext> = {
|
export const componentsPluginTemplate: NuxtPluginTemplate<ComponentsTemplateContext> = {
|
||||||
filename: 'components.plugin.mjs',
|
filename: 'components.plugin.mjs',
|
||||||
getContents ({ app }) {
|
getContents ({ app }) {
|
||||||
const globalComponents = app.components.filter(c => c.global)
|
const globalComponents = new Set<string>()
|
||||||
if (!globalComponents.length) { return emptyComponentsPlugin }
|
for (const component of app.components) {
|
||||||
|
if (component.global) {
|
||||||
|
globalComponents.add(component.pascalName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!globalComponents.size) { return emptyComponentsPlugin }
|
||||||
|
|
||||||
|
const components = [...globalComponents]
|
||||||
|
|
||||||
return `import { defineNuxtPlugin } from '#app/nuxt'
|
return `import { defineNuxtPlugin } from '#app/nuxt'
|
||||||
import { ${globalComponents.map(c => 'Lazy' + c.pascalName).join(', ')} } from '#components'
|
import { ${components.map(c => 'Lazy' + c).join(', ')} } from '#components'
|
||||||
const lazyGlobalComponents = [
|
const lazyGlobalComponents = [
|
||||||
${globalComponents.map(c => `["${c.pascalName}", Lazy${c.pascalName}]`).join(',\n')}
|
${components.map(c => `["${c}", Lazy${c}]`).join(',\n')}
|
||||||
]
|
]
|
||||||
|
|
||||||
export default defineNuxtPlugin({
|
export default defineNuxtPlugin({
|
||||||
|
5
test/fixtures/basic/components/global/ClientGlobal.client.vue
vendored
Normal file
5
test/fixtures/basic/components/global/ClientGlobal.client.vue
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<template>
|
||||||
|
<div>
|
||||||
|
global component (client-only) registered automatically
|
||||||
|
</div>
|
||||||
|
</template>
|
Loading…
Reference in New Issue
Block a user