chore: extract i18n hmr plugin to base

Signed-off-by: Innei <i@innei.in>
This commit is contained in:
Innei 2024-09-12 12:10:11 +08:00
parent 5d27d29e4b
commit 9024b6a497
No known key found for this signature in database
GPG Key ID: 0F62D33977F021F7
2 changed files with 19 additions and 19 deletions

View File

@ -52,6 +52,25 @@ export const viteRenderBaseConfig = {
}),
viteTwToRawString(),
{
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 []
}
},
},
],
define: {
APP_VERSION: JSON.stringify(pkg.version),

View File

@ -1,4 +1,3 @@
import { readFileSync } from "node:fs"
import { resolve } from "node:path"
import { fileURLToPath } from "node:url"
@ -98,24 +97,6 @@ export default ({ mode }) => {
devPrint(),
{
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 []
}
},
},
process.env.ANALYZER && analyzer(),
],
define: {