perf!(nuxt3): disable global components by default (#3305)

This commit is contained in:
Daniel Roe 2022-02-18 09:37:11 +00:00 committed by GitHub
parent 3d258d304e
commit 87eb7d0d39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -68,6 +68,7 @@ export default defineNuxtModule<ComponentsOptions>({
} }
return { return {
global: componentOptions.global,
...dirOptions, ...dirOptions,
// TODO: https://github.com/nuxt/framework/pull/251 // TODO: https://github.com/nuxt/framework/pull/251
enabled: true, enabled: true,

View File

@ -28,7 +28,7 @@ export const componentsTemplate = {
getContents ({ options }: { options: ComponentsTemplateOptions }) { getContents ({ options }: { options: ComponentsTemplateOptions }) {
return `import { defineAsyncComponent } from 'vue' 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 exp = c.export === 'default' ? 'c.default || c' : `c['${c.export}']`
const comment = createImportMagicComments(c) const comment = createImportMagicComments(c)

View File

@ -92,5 +92,16 @@ export interface ComponentsDir extends ScanDir {
export interface ComponentsOptions { export interface ComponentsOptions {
dirs: (string | ComponentsDir)[] 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 `<component :is="`icon-${myIcon}`">`.
*
* This can be overridden by an individual component directory entry.
*
* @default false
*/
global?: boolean
loader?: boolean loader?: boolean
} }