From 87eb7d0d392e2fb1ed36cdb8f4c96c69720c2276 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 18 Feb 2022 09:37:11 +0000 Subject: [PATCH] perf!(nuxt3): disable global components by default (#3305) --- packages/nuxt3/src/components/module.ts | 1 + packages/nuxt3/src/components/templates.ts | 2 +- packages/schema/src/types/components.ts | 11 +++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) 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 }