feat(kit): support prepend option for addComponentsDir (#24309)

This commit is contained in:
Sadegh Barati 2023-11-24 00:43:03 +03:30 committed by GitHub
parent 4ce6bc244c
commit be11bac9c2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,12 +9,12 @@ import { logger } from './logger'
*
* Requires Nuxt 2.13+
*/
export async function addComponentsDir (dir: ComponentsDir) {
export async function addComponentsDir (dir: ComponentsDir, opts: { prepend?: boolean } = {}) {
const nuxt = useNuxt()
await assertNuxtCompatibility({ nuxt: '>=2.13' }, nuxt)
nuxt.options.components = nuxt.options.components || []
dir.priority ||= 0
nuxt.hook('components:dirs', (dirs) => { dirs.push(dir) })
nuxt.hook('components:dirs', (dirs) => { dirs[opts.prepend ? 'unshift' : 'push'](dir) })
}
export type AddComponentOptions = { name: string, filePath: string } & Partial<Exclude<Component,