Files
afilmory/apps/web/plugins/vite/i18n-hmr.ts
Innei 6668425fba feat: add Vite plugins for enhanced functionality and localization support
- Introduced multiple Vite plugins including `ogImagePlugin`, `feedSitemapPlugin`, `localesJsonPlugin`, and `manifestInjectPlugin` to enhance the build process and support dynamic content generation.
- Implemented a custom hot module replacement (HMR) for JSON localization files to improve development experience.
- Added a new `createDependencyChunksPlugin` for better chunk management in the build process.
- Established a structure for handling localization files and generating corresponding assets, improving internationalization support.

Signed-off-by: Innei <tukon479@gmail.com>
2025-06-27 16:58:12 +08:00

25 lines
558 B
TypeScript

import { readFileSync } from 'node:fs'
import type { Plugin } from 'vite'
export function customI18nHmrPlugin(): Plugin {
return {
name: 'custom-i18n-hmr',
handleHotUpdate({ file, server }) {
if (file.endsWith('.json') && file.includes('locales')) {
server.ws.send({
type: 'custom',
event: 'i18n-update',
data: {
file,
content: readFileSync(file, 'utf-8'),
},
})
// return empty array to prevent the default HMR
return []
}
},
}
}