mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-02 02:17:15 +00:00
Merge branch 'main' into sort-plugins
This commit is contained in:
commit
8f4ddeff27
@ -12,6 +12,7 @@ export async function addComponentsDir (dir: ComponentsDir) {
|
|||||||
const nuxt = useNuxt()
|
const nuxt = useNuxt()
|
||||||
await assertNuxtCompatibility({ nuxt: '>=2.13' }, nuxt)
|
await assertNuxtCompatibility({ nuxt: '>=2.13' }, nuxt)
|
||||||
nuxt.options.components = nuxt.options.components || []
|
nuxt.options.components = nuxt.options.components || []
|
||||||
|
dir.priority ||= 0
|
||||||
nuxt.hook('components:dirs', (dirs) => { dirs.push(dir) })
|
nuxt.hook('components:dirs', (dirs) => { dirs.push(dir) })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr
|
|||||||
shortPath,
|
shortPath,
|
||||||
export: 'default',
|
export: 'default',
|
||||||
// by default, give priority to scanned components
|
// by default, give priority to scanned components
|
||||||
priority: 1
|
priority: dir.priority ?? 1
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof dir.extendComponent === 'function') {
|
if (typeof dir.extendComponent === 'function') {
|
||||||
@ -135,9 +135,15 @@ export async function scanComponents (dirs: ComponentsDir[], srcDir: string): Pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
const existingComponent = components.find(c => c.pascalName === component.pascalName && ['all', component.mode].includes(c.mode))
|
const existingComponent = components.find(c => c.pascalName === component.pascalName && ['all', component.mode].includes(c.mode))
|
||||||
|
// Ignore component if component is already defined (with same mode)
|
||||||
if (existingComponent) {
|
if (existingComponent) {
|
||||||
// Ignore component if component is already defined (with same mode)
|
const existingPriority = existingComponent.priority ?? 0
|
||||||
warnAboutDuplicateComponent(componentName, filePath, existingComponent.filePath)
|
const newPriority = component.priority ?? 0
|
||||||
|
|
||||||
|
if (newPriority >= existingPriority) {
|
||||||
|
warnAboutDuplicateComponent(componentName, filePath, existingComponent.filePath)
|
||||||
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,6 +85,14 @@ export interface ComponentsDir extends ScanDir {
|
|||||||
* By default ('auto') it will set transpile: true if node_modules/ is in path.
|
* By default ('auto') it will set transpile: true if node_modules/ is in path.
|
||||||
*/
|
*/
|
||||||
transpile?: 'auto' | boolean
|
transpile?: 'auto' | boolean
|
||||||
|
/**
|
||||||
|
* This number allows configuring the behavior of overriding Nuxt components.
|
||||||
|
* It will be inherited by any components within the directory.
|
||||||
|
*
|
||||||
|
* If multiple components are provided with the same name, then higher priority
|
||||||
|
* components will be used instead of lower priority components.
|
||||||
|
*/
|
||||||
|
priority?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ComponentsOptions {
|
export interface ComponentsOptions {
|
||||||
|
Loading…
Reference in New Issue
Block a user