Hey ... I'm writing an artical on this in the context of dashboards.... But I'll answer your question for now. Reason for this is the vite plugin that is available is not currently supporting this behavior... There are few alternative but hacky ways you can do this but it require you building the plugin with few new function implementations, which is not intuitive. For now what I recommend is use webpack for such scenarios as you can use vite and webpack side by side as vite supports webpack builds.
I will try to address this in my next article 🙂