mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-19 01:45:53 +00:00
docs: update auto-imports to advertise the scan feature (#30292)
This commit is contained in:
parent
05f17b7041
commit
d9aab7a21a
@ -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`.
|
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 system’s override feature. If you use `imports.scan: false`, ensure you understand this side-effect and adjust your architecture accordingly.
|
||||||
|
::
|
||||||
|
|
||||||
## Auto-imported Components
|
## Auto-imported Components
|
||||||
|
|
||||||
Nuxt also automatically imports components from your `~/components` directory, although this is configured separately from auto-importing composables and utility functions.
|
Nuxt also automatically imports components from your `~/components` directory, although this is configured separately from auto-importing composables and utility functions.
|
||||||
|
@ -28,6 +28,11 @@ export default defineUntypedSchema({
|
|||||||
*/
|
*/
|
||||||
imports: {
|
imports: {
|
||||||
global: false,
|
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.
|
* An array of custom directories that will be auto-imported.
|
||||||
|
Loading…
Reference in New Issue
Block a user