Skip to content

Commit

Permalink
feat: register component/content as non-global components
Browse files Browse the repository at this point in the history
  • Loading branch information
farnabaz committed Nov 5, 2024
1 parent 705aab7 commit cda951f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { mkdir, readFile } from 'node:fs/promises'
import { mkdir, readFile, stat } from 'node:fs/promises'
import {
defineNuxtModule,
createResolver,
Expand Down Expand Up @@ -133,6 +133,18 @@ export default defineNuxtModule<ModuleOptions>({
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)
Expand Down

0 comments on commit cda951f

Please sign in to comment.