docs: add note about nested directory order (#19061)

This commit is contained in:
Daniel Roe 2023-02-15 16:22:30 +00:00 committed by GitHub
parent 80f73d39ce
commit 6c5d8d6b2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -27,13 +27,30 @@ Nuxt automatically imports any components in your `components/` directory (along
</template>
```
## Custom directories
By default, only the `~/components` directory is scanned. If you want to add other directories, or change how the components are scanned within a subfolder of this directory, you can add additional directories to the configuration:
```js
export default defineNuxtConfig({
components: [
{ '~/components/special-components', prefix: 'Special' },
'~/components',
]
})
```
::alert
Any nested directories need to be added first as they are scanned in order.
::
## Component extensions
By default, any file with an extension specified in the [extensions key of `nuxt.config.ts`](/api/configuration/nuxt-config#extensions) is treated as a component.
If you need to restrict the file extensions that should be registered as components, you can use the extended form of the components directory declaration and its `extensions` key:
```diff
export default defineNuxtModule({
export default defineNuxtConfig({
components: [
{
path: '~/components',
@ -70,7 +87,7 @@ If you want to auto-import components based only on its name, not path, then you
export default defineNuxtConfig({
components: [
{
path: '~/components/',
path: '~/components',
+ pathPrefix: false,
},
],