Skip to content

Commit

Permalink
perf!(nuxt3): disable global components by default (nuxt#3305)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe authored Feb 18, 2022
1 parent 3d258d3 commit 87eb7d0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/nuxt3/src/components/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default defineNuxtModule<ComponentsOptions>({
}

return {
global: componentOptions.global,
...dirOptions,
// TODO: https://github.com/nuxt/framework/pull/251
enabled: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt3/src/components/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions packages/schema/src/types/components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<component :is="`icon-${myIcon}`">`.
*
* This can be overridden by an individual component directory entry.
*
* @default false
*/
global?: boolean
loader?: boolean
}

0 comments on commit 87eb7d0

Please sign in to comment.