Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

189
Views
¿Cómo ver el directorio público en el proyecto Vite para recargar en caliente?

Tengo un proyecto de reacción configurado con Vite.
La recarga en caliente funciona muy bien, pero uso react-i18next para soporte de múltiples idiomas y esta es mi estructura:

 public -> en -> translation.json -> ru -> translation.json

Cuando cambio los archivos translation.json , Vite no los ve y tengo que actualizar la página para ver los cambios.

¿Hay alguna manera de decirle a Vite que mire todos los archivos en el directorio public ?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Puedes lograr eso con un plugin.

Cometí un error en mi primera respuesta, debería ser un evento full-reload y no un evento de update

 export default function CustomHmr() { return { name: 'custom-hmr', enforce: 'post', // HMR handleHotUpdate({ file, server }) { if (file.endsWith('.json')) { console.log('reloading json file...'); server.ws.send({ type: 'full-reload', path: '*' }); } }, } }

luego agregue el complemento en vite.config.js :

 { plugins: [ CustomHmr() <--- custom plugin ] }

💡 Te hice un repositorio en Github con un ejemplo de trabajo:

  • https://github.com/flydev-fr/vite-react-i18next

Ilustración de resultados

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza Report

0

Modifiqué la respuesta de flydev para que pueda recargar en caliente los componentes dependientes de i18n sin recargar toda la página. (Actualmente usando en un proyecto mecanografiado)

 import { PluginOption } from "vite"; export default function I18nHotReload(): PluginOption { return { name: 'i18n-hot-reload', handleHotUpdate({ file, server }) { if (file.includes('locales') && file.endsWith('.json')) { console.log('Locale file updated') server.ws.send({ type: "custom", event: "locales-update", }); } }, } }

Luego agregándolo a los complementos de vite:

 plugins: [ ..., i18nHotReload(), ]

Y luego agregar el oyente en cualquier lugar al que pueda llegar su código (lo estoy usando en el archivo de configuración inicial i18n)

 if (import.meta.hot) { import.meta.hot.on('locales-update', () => { i18n.reloadResources().then(() => { i18n.changeLanguage(i18n.language) }) }) }

i18n.reloadResources() solo no activa la recarga en caliente de las traducciones

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!