diff --git a/packages/nuxt/src/components/templates.ts b/packages/nuxt/src/components/templates.ts index fa2c7eb6d1ce..0c1a281a1b10 100644 --- a/packages/nuxt/src/components/templates.ts +++ b/packages/nuxt/src/components/templates.ts @@ -36,13 +36,20 @@ export default defineNuxtPlugin({ export const componentsPluginTemplate: NuxtPluginTemplate = { filename: 'components.plugin.mjs', getContents ({ app }) { - const globalComponents = app.components.filter(c => c.global) - if (!globalComponents.length) { return emptyComponentsPlugin } + const globalComponents = new Set() + 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' -import { ${globalComponents.map(c => 'Lazy' + c.pascalName).join(', ')} } from '#components' +import { ${components.map(c => 'Lazy' + c).join(', ')} } from '#components' const lazyGlobalComponents = [ - ${globalComponents.map(c => `["${c.pascalName}", Lazy${c.pascalName}]`).join(',\n')} + ${components.map(c => `["${c}", Lazy${c}]`).join(',\n')} ] export default defineNuxtPlugin({ diff --git a/test/fixtures/basic/components/global/ClientGlobal.client.vue b/test/fixtures/basic/components/global/ClientGlobal.client.vue new file mode 100644 index 000000000000..dfcd008e1ba6 --- /dev/null +++ b/test/fixtures/basic/components/global/ClientGlobal.client.vue @@ -0,0 +1,5 @@ +