Skip to content

Commit cda951f

Browse files
committed
feat: register component/content as non-global components
1 parent 705aab7 commit cda951f

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/module.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { mkdir, readFile } from 'node:fs/promises'
1+
import { mkdir, readFile, stat } from 'node:fs/promises'
22
import {
33
defineNuxtModule,
44
createResolver,
@@ -133,6 +133,18 @@ export default defineNuxtModule<ModuleOptions>({
133133
nuxt.options.alias['#content/components'] = addTemplate(componentsManifestTemplate(manifest)).dst
134134
nuxt.options.alias['#content/manifest'] = addTemplate(manifestTemplate(manifest)).dst
135135

136+
// Register user components
137+
const _layers = [...nuxt.options._layers].reverse()
138+
for (const layer of _layers) {
139+
const path = resolver.resolve(layer.config.srcDir, 'components/content')
140+
const dirStat = await stat(path).catch(() => null)
141+
if (dirStat && dirStat.isDirectory()) {
142+
nuxt.hook('components:dirs', (dirs) => {
143+
dirs.unshift({ path, pathPrefix: false, prefix: '' })
144+
})
145+
}
146+
}
147+
136148
// Load preset
137149
nuxt.hook('nitro:config', async (config) => {
138150
const preset = findPreset(nuxt)

0 commit comments

Comments
 (0)