From be11bac9c26ebba5cf8ddc1e8e3d1c1cb5838e11 Mon Sep 17 00:00:00 2001 From: Sadegh Barati Date: Fri, 24 Nov 2023 00:43:03 +0330 Subject: [PATCH] feat(kit): support prepend option for `addComponentsDir` (#24309) --- packages/kit/src/components.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/kit/src/components.ts b/packages/kit/src/components.ts index e344b7a95a..365bf514af 100644 --- a/packages/kit/src/components.ts +++ b/packages/kit/src/components.ts @@ -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