diff --git a/packages/nuxt3/src/components/module.ts b/packages/nuxt3/src/components/module.ts index 22f504c6cc..36ed096675 100644 --- a/packages/nuxt3/src/components/module.ts +++ b/packages/nuxt3/src/components/module.ts @@ -68,6 +68,7 @@ export default defineNuxtModule({ } return { + global: componentOptions.global, ...dirOptions, // TODO: https://github.com/nuxt/framework/pull/251 enabled: true, diff --git a/packages/nuxt3/src/components/templates.ts b/packages/nuxt3/src/components/templates.ts index 25b4f5d60e..1073d7f6b8 100644 --- a/packages/nuxt3/src/components/templates.ts +++ b/packages/nuxt3/src/components/templates.ts @@ -28,7 +28,7 @@ export const componentsTemplate = { getContents ({ options }: { options: ComponentsTemplateOptions }) { return `import { defineAsyncComponent } from 'vue' -const components = ${genObjectFromRawEntries(options.components.filter(c => c.global !== false).map((c) => { +const components = ${genObjectFromRawEntries(options.components.filter(c => c.global === true).map((c) => { const exp = c.export === 'default' ? 'c.default || c' : `c['${c.export}']` const comment = createImportMagicComments(c) diff --git a/packages/schema/src/types/components.ts b/packages/schema/src/types/components.ts index a0169ae192..a575cf995d 100644 --- a/packages/schema/src/types/components.ts +++ b/packages/schema/src/types/components.ts @@ -92,5 +92,16 @@ export interface ComponentsDir extends ScanDir { export interface ComponentsOptions { dirs: (string | ComponentsDir)[] + /** + * The default value for whether to globally register components. + * + * When components are registered globally, they will still be directly imported where used, + * but they can also be used dynamically, for example ``. + * + * This can be overridden by an individual component directory entry. + * + * @default false + */ + global?: boolean loader?: boolean }