@nuxt/kit: Add prepend option to addImportsDir
Describe the feature
As a module author, I would like my composables defined inside the module to be customizable by the app, in case some customization is needed. it very simple in nuxt to do that by using imports:dirs hook
nuxt.hook('imports:dirs', (_dirs) => {
_dirs.unshift(MODULE_COMPOSABLE_DIR)
})
But it would be best to add a simple prepend flag to the addImportsDir, just like the plugin kit utilities defined in https://github.com/nuxt/nuxt/blob/main/packages/kit/src/plugin.ts
Additional information
- [X] Would you be willing to help implement this feature?
- [ ] Could this feature be implemented as a module?
Final checks
- [X] Read the contribution guide.
- [X] Check existing discussions and issues.
What is the reason you want to prepend import directories? We have the priority property that should allow you to configure which directory/import takes priority over another.
Well, addImportsDir only accepts a string or an array of string. it's not possible to use a priority property.
For my use case, i have a directory in a internal module that houses many composables which i want to be registered to the nuxt app (I use addImportsDir from @nuxt/kit). I also want to be able to override any imports from that directory from the app's ~/composables
I achieved exactly that with the included snippet.
Similiar to the code from addPlugin. where we can pass an append option
https://github.com/nuxt/nuxt/blob/main/packages/kit/src/plugin.ts

Seems like a good idea to me unless @antfu has a different POV...
It makes sense to me as well. 👍