Skip to content

Commit bacda79

Browse files
authored
fix(global-components): handle components registered using addComponent util (#65)
1 parent 032ff4a commit bacda79

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/module.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,16 @@ export default defineNuxtModule<ModuleOptions>({
118118
]
119119
parserOptions.componentDirs = componentDirs
120120
})
121+
122+
// Add global components path to handle components added with `addComponent` utility
123+
nuxt.hook('components:extend', (_components) => {
124+
_components.forEach((c) => {
125+
if (c.global) {
126+
parserOptions.componentDirs.push(c.filePath)
127+
}
128+
})
129+
})
130+
121131
nuxt.hook('components:extend', async (_components) => {
122132
components = _components
123133

src/parser.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,13 @@ export function useComponentMetaParser (
9191
skipLibCheck: true,
9292
include: [
9393
'**/*',
94-
...componentDirs.map(dir => `${typeof dir === 'string' ? dir : (dir?.path || '')}/**/*`)
94+
...componentDirs.map((dir) => {
95+
const path = typeof dir === 'string' ? dir : (dir?.path || '')
96+
if (path.endsWith('.vue')) {
97+
return path
98+
}
99+
return `${path}/**/*`
100+
})
95101
],
96102
exclude: []
97103
},

0 commit comments

Comments
 (0)