Auto-import only Nuxt and Vue features but no custom or third party code
Hey! I wonder: is it possible to disable auto imports for components, composables, and utils while keeping Nuxt and Vue auto-imports enabled? If yes: how? Thx!
2 Replies
Hey @maoberlehner , it looks that there is no a built in way to do what you are asking for.
First of all we need to understand the imports config.
You have 2 different imports, one for components and other for utilities(composables, utilities and libraries).
Components auto import is easy to be disabled, you just need to do:
The problem is with the utilities auto import.
You can disable utilities auto imports with this:
The problem with this config is that:
- Auto imports are not totally disabled. You can check that .nuxt/imports.d.ts is showing all the imports types.
- Any import you add manually is disabled, from config and modules. You will see that they are at .nuxt/imports.d.ts, but they will not be imported at runtime
- You can use the imports with '#imports' path
- If you define for example
imports.presets: ['vue']
, vite will throw an error
The only way that you can achive this right now is with something like that:
You can play with this configs at: https://stackblitz.com/edit/nuxt-starter-xuhfai?file=nuxt.config.tsJuanp
StackBlitz
nuxt 3 - auto import POC - StackBlitz
Create a new Nuxt project, module, layer or start from a theme with our collection of starters.
@maoberlehner FYI: https://github.com/nuxt/nuxt/pull/26576
GitHub
feat(nuxt): introduce
imports.scan
option by antfu · Pull Request...🔗 Linked issue
#26525
📚 Description
I think auto imports for local composables are the main source of implicitness we have for auto imports.
This PR introduced the imports.scan: false option to dis...