docs: update auto-imports to advertise the scan feature (#30292)

This commit is contained in:
derHodrig 2024-12-18 10:37:34 +01:00 committed by Daniel Roe
parent 05f17b7041
commit d9aab7a21a
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B
2 changed files with 27 additions and 0 deletions

View File

@ -143,6 +143,28 @@ export default defineNuxtConfig({
This will disable auto-imports completely but it's still possible to use [explicit imports](#explicit-imports) from `#imports`.
### Partially Disabling Auto-imports
If you want framework-specific functions like `ref` to remain auto-imported but wish to disable auto-imports for your own code (e.g., custom composables), you can set the `imports.scan` option to `false` in your `nuxt.config.ts` file:
```ts
export default defineNuxtConfig({
imports: {
scan: false
}
})
```
With this configuration:
- Framework functions like `ref`, `computed`, or `watch` will still work without needing manual imports.
- Custom code, such as composables, will need to be manually imported in your files.
::warning
**Caution:** This setup has certain limitations:
- If you structure your project with layers, you will need to explicitly import the composables from each layer, rather than relying on auto-imports.
- This breaks the layer systems override feature. If you use `imports.scan: false`, ensure you understand this side-effect and adjust your architecture accordingly.
::
## Auto-imported Components
Nuxt also automatically imports components from your `~/components` directory, although this is configured separately from auto-importing composables and utility functions.

View File

@ -28,6 +28,11 @@ export default defineUntypedSchema({
*/
imports: {
global: false,
/**
* Whether to scan your `composables/` and `utils/` directories for composables to auto-import.
* Auto-imports registered by Nuxt or other modules, such as imports from `vue` or `nuxt`, will still be enabled.
*/
scan: true,
/**
* An array of custom directories that will be auto-imported.