diff --git a/docs/content/1.docs/2.guide/2.directory-structure/1.composables.md b/docs/content/1.docs/2.guide/2.directory-structure/1.composables.md index bd7e9f5153a..465c192964c 100644 --- a/docs/content/1.docs/2.guide/2.directory-structure/1.composables.md +++ b/docs/content/1.docs/2.guide/2.directory-structure/1.composables.md @@ -82,10 +82,11 @@ composables | - index.ts // scanned | - useFoo.ts // scanned | - nested + | --- index.ts // scanned | --- utils.ts // not scanned ``` -Only `composables/index.ts` and `composables/useFoo.ts` would be searched for imports. +Only `composables/index.ts`, `composables/useFoo.ts` and `composables/nested/index.ts` would be searched for imports. To get auto imports working for nested modules, you could either re-export them (recommended) or configure the scanner to include nested directories: diff --git a/packages/nuxt/src/imports/module.ts b/packages/nuxt/src/imports/module.ts index a26d941de1d..01f1c6731bb 100644 --- a/packages/nuxt/src/imports/module.ts +++ b/packages/nuxt/src/imports/module.ts @@ -49,7 +49,9 @@ export default defineNuxtModule>({ let composablesDirs: string[] = [] for (const layer of nuxt.options._layers) { composablesDirs.push(resolve(layer.config.srcDir, 'composables')) + composablesDirs.push(resolve(layer.config.srcDir, 'composables/*/index.{ts,js,mjs,mts}')) composablesDirs.push(resolve(layer.config.srcDir, 'utils')) + composablesDirs.push(resolve(layer.config.srcDir, 'utils/*/index.{ts,js,mjs,mts}')) for (const dir of (layer.config.imports?.dirs ?? [])) { if (!dir) { continue