unplugin-vue-components icon indicating copy to clipboard operation
unplugin-vue-components copied to clipboard

Vite HMR doesn't work for custom resolvers?

Open AaronBeaudoin opened this issue 3 years ago • 6 comments

If I use the following config:

VueComponentsPlugin({
  dirs: ["components"]
})

...and use a file ./components/Button.vue as <Button>, HMR works great.

However, if I use a config with a custom resolver like for example:

function CustomResolver(path) {
  return name => {
    if (!name.startsWith("Custom")) return;
    return pathTools.join(__dirname, path, `${toKebabCase(name.slice(6))}.vue`);
  };
}

VueComponentsPlugin({
  resolvers: [CustomResolver("components")]
})

...the component resolves and imports correctly when used as <CustomButton>, but updates to the component are not recognized until a full server restart. Not even refreshing the page will let me see my changes to the component.

I also tried ensuring dirs is specified (in case that option is used to define where to watch):

VueComponentsPlugin({
  dirs: ["components"],
  resolvers: [CustomResolver("components")]
})

...however this doesn't really change anything. In this case I can use the file as <Button> and HMR works, but if I use it as <CustomButton> HMR doesn't work and a full server restart is required.

I am using v0.17.2.

AaronBeaudoin avatar Dec 07 '21 22:12 AaronBeaudoin

Can you share a minimal reproduction? Thanks.

antfu avatar Dec 08 '21 06:12 antfu

Minimal reproduction (README has steps to reproduce):

https://github.com/AaronBeaudoin/unplugin-vue-components-test

AaronBeaudoin avatar Dec 08 '21 15:12 AaronBeaudoin

@antfu Just checking to see if you've had a chance to run the minimal reproduction and identify the issue?

AaronBeaudoin avatar Dec 09 '21 17:12 AaronBeaudoin

@antfu Just pinging this since it's been a little over a week. Would you happen to know why this is happening?

AaronBeaudoin avatar Dec 17 '21 18:12 AaronBeaudoin

Does anyone know why components don't update when imported with a custom resolver?

AaronBeaudoin avatar Dec 28 '21 16:12 AaronBeaudoin

Was this fixed at some point, I updated to the newest version and everything seems to be working...?

AaronBeaudoin avatar Jan 20 '22 16:01 AaronBeaudoin