Skip to content
Advertisement

How to watch public directory in Vite project for hot-reload?

I have a react project configured with Vite.
Hot reload works great, but I use react-i18next for multiple language support and this is my structure:

JavaScript

When I change the translation.json files, Vite doesn’t watch it, and I have to refresh the page to see the changes.

Is there a way to tell Vite to watch all the files in the public directory?

Advertisement

Answer

You can achieve that with a plugin.

I made a mistake on my first answer, it should be a full-reload event and not a update event

JavaScript

then add the plugin in vite.config.js :

JavaScript

💡 I made you a repo on Github with a working example:

Result Illustration

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement