From cda951f1139ee92e4b9862ad17cf823b71d56af8 Mon Sep 17 00:00:00 2001 From: Farnabaz Date: Tue, 5 Nov 2024 08:59:07 +0100 Subject: [PATCH] feat: register `component/content` as non-global components --- src/module.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/module.ts b/src/module.ts index 5b8d7544d..4f341c372 100644 --- a/src/module.ts +++ b/src/module.ts @@ -1,4 +1,4 @@ -import { mkdir, readFile } from 'node:fs/promises' +import { mkdir, readFile, stat } from 'node:fs/promises' import { defineNuxtModule, createResolver, @@ -133,6 +133,18 @@ export default defineNuxtModule({ nuxt.options.alias['#content/components'] = addTemplate(componentsManifestTemplate(manifest)).dst nuxt.options.alias['#content/manifest'] = addTemplate(manifestTemplate(manifest)).dst + // Register user components + const _layers = [...nuxt.options._layers].reverse() + for (const layer of _layers) { + const path = resolver.resolve(layer.config.srcDir, 'components/content') + const dirStat = await stat(path).catch(() => null) + if (dirStat && dirStat.isDirectory()) { + nuxt.hook('components:dirs', (dirs) => { + dirs.unshift({ path, pathPrefix: false, prefix: '' }) + }) + } + } + // Load preset nuxt.hook('nitro:config', async (config) => { const preset = findPreset(nuxt)