mirror of
https://github.com/Afilmory/afilmory
synced 2026-02-01 22:48:17 +00:00
- 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>
33 lines
761 B
TypeScript
33 lines
761 B
TypeScript
|
|
import { set } from 'es-toolkit/compat'
|
|
import type { Plugin } from 'vite'
|
|
|
|
import { MONOREPO_ROOT_PATH } from './__internal__/constants'
|
|
|
|
export function localesJsonPlugin(): Plugin {
|
|
return {
|
|
name: 'locales-json-transform',
|
|
enforce: 'pre',
|
|
|
|
async transform(code, id) {
|
|
if (!id.includes(MONOREPO_ROOT_PATH) || !id.endsWith('.json')) {
|
|
return null
|
|
}
|
|
|
|
const content = JSON.parse(code)
|
|
const obj = {}
|
|
|
|
const keys = Object.keys(content as object)
|
|
for (const accessorKey of keys) {
|
|
set(obj, accessorKey, (content as any)[accessorKey])
|
|
}
|
|
|
|
console.info('[locales-json-transform] Transformed:', id)
|
|
return {
|
|
code: JSON.stringify(obj),
|
|
map: null,
|
|
}
|
|
},
|
|
}
|
|
}
|