You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way component resoution works is that a component map is generated from your dirs and if nothing matches that map, then it uses the custom resolvers.
There's no options, transforms, filters or callbacks that have any ability to affect this component map creation.
Technically speaking, for an MVP, all you would need to do is insert a prefix here:
There's a pull request (#612) that's been languishing for over 2 years, so I doubt anything is ever going to happen in implementing this feature.
There's a pretty easy workaround though... just put all your components inside a subfolder with your prefix as its name and then enable directoryAsNamespace.
You can create a custom resolver adding the prefix option, check this resolver to allow prefixing all Vuetify components using VuetifyXXX instead VXXX (we only allow prefix as a boolean, but you can allow any prefix, the logic in that case should be changed):
Asking “why” is a strange question for software development.
A plug-in like this has thousands of users with complex, unpredictable and varied needs in infinite different contexts.
“Why not” is always the better question.
Personally, it’s a DX issue where it helps to quickly know where a component is coming from if I’m using them from many different sources in the same project.
But others might have more functionality-based needs.
Activity
kasperskov-pdk commentedon Sep 1, 2022
Would be nice.
I tried
Does not work. The resolver is only for resolving the path.
RuBaWa commentedon Oct 14, 2022
Do you have found a solution?
I also want to prefix all my components. For example:
WButton
should resolvesrc/components/Button.vue
Veseron commentedon Oct 16, 2022
The returned object also needs a "from" property.
But I can't figure out how to do it right.
acibilous commentedon Jun 14, 2023
any updates?
simonmaass commentedon Jun 7, 2024
did anyone get this to work?
craigrileyuk commentedon May 3, 2025
It requires some coding changes for this to work.
The way component resoution works is that a component map is generated from your
dirs
and if nothing matches that map, then it uses the custom resolvers.There's no options, transforms, filters or callbacks that have any ability to affect this component map creation.
Technically speaking, for an MVP, all you would need to do is insert a prefix here:
unplugin-vue-components/src/core/context.ts
Line 228 in 63d5c7e
before the
name
variable.There's a pull request (#612) that's been languishing for over 2 years, so I doubt anything is ever going to happen in implementing this feature.
There's a pretty easy workaround though... just put all your components inside a subfolder with your prefix as its name and then enable
directoryAsNamespace
.userquin commentedon May 3, 2025
You can create a custom resolver adding the prefix option, check this resolver to allow prefixing all Vuetify components using VuetifyXXX instead VXXX (we only allow prefix as a boolean, but you can allow any prefix, the logic in that case should be changed):
https://github.com/userquin/unvuetify-monorepo/blob/main/packages/unplugin-vue-components-resolvers/src/index.ts#L62-L96
craigrileyuk commentedon May 3, 2025
The problem with using a custom resolver is that you lose access to all the filters like
directoryAsNamespace
et al.You have to reimplement everything yourself.
It’d be far preferable to be able to specify a prefix for components in the vite plug-in config.
userquin commentedon May 3, 2025
then, why do you need to add a prefix?
craigrileyuk commentedon May 3, 2025
Asking “why” is a strange question for software development.
A plug-in like this has thousands of users with complex, unpredictable and varied needs in infinite different contexts.
“Why not” is always the better question.
Personally, it’s a DX issue where it helps to quickly know where a component is coming from if I’m using them from many different sources in the same project.
But others might have more functionality-based needs.
userquin commentedon May 3, 2025
directoryAsNamespace
should only be applied to your local components not to third party dependencies, that's why I'm asking whycraigrileyuk commentedon May 3, 2025
Because you suggested using a custom resolver to add a prefix to local components…
userquin commentedon May 4, 2025
Oh, sorry, this issue is about prefixing local components without using directory as namespace option, I will try to add the prefix feature.