@analogjs/vite-plugin-nitro
Version:
A Vite plugin for adding a nitro API server
25 lines • 846 B
JavaScript
/**
* Registers a file watcher that triggers a full page reload
* when translation files are added or modified.
*
* Matches files in i18n directories with .json, .xlf, .xmb, or .arb extensions.
*
* @param viteServer The Vite development server instance
*/
export function registerI18nWatcher(viteServer) {
const triggerReload = (path) => {
if (isTranslationFile(path)) {
viteServer.ws.send({ type: 'full-reload' });
}
};
viteServer.watcher.on('change', triggerReload);
viteServer.watcher.on('add', triggerReload);
}
/**
* Checks whether a file path looks like a translation file
* based on its location in an i18n directory and its extension.
*/
export function isTranslationFile(path) {
return /i18n.*\.(json|xlf|xmb|arb)$/.test(path);
}
//# sourceMappingURL=register-i18n-watcher.js.map