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>
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import type { Plugin, UserConfig } from 'vite'
|
|
|
|
export function createDependencyChunksPlugin(dependencies: string[][]): Plugin {
|
|
return {
|
|
name: 'dependency-chunks',
|
|
config(config: UserConfig) {
|
|
config.build = config.build || {}
|
|
config.build.rollupOptions = config.build.rollupOptions || {}
|
|
config.build.rollupOptions.output =
|
|
config.build.rollupOptions.output || {}
|
|
|
|
const { output } = config.build.rollupOptions
|
|
const outputConfig = Array.isArray(output) ? output[0] : output
|
|
outputConfig.assetFileNames = 'assets/[name].[hash:6][extname]'
|
|
outputConfig.chunkFileNames = (chunkInfo) => {
|
|
return chunkInfo.name.startsWith('vendor/')
|
|
? '[name]-[hash].js'
|
|
: 'assets/[name]-[hash].js'
|
|
}
|
|
|
|
outputConfig.manualChunks = (id: string, { getModuleInfo }) => {
|
|
const moduleInfo = getModuleInfo(id)
|
|
if (
|
|
moduleInfo?.dynamicImporters?.length &&
|
|
moduleInfo?.importers?.length
|
|
) {
|
|
return null
|
|
}
|
|
|
|
const matchedDep = dependencies.findIndex((dep) => {
|
|
return dep.some((d) => {
|
|
const pattern = `/node_modules/${d}/`
|
|
return (
|
|
id.includes(pattern) && !id.includes(`${pattern}node_modules/`)
|
|
)
|
|
})
|
|
})
|
|
|
|
if (matchedDep !== -1) {
|
|
return `vendor/${matchedDep}`
|
|
}
|
|
|
|
return null
|
|
}
|
|
},
|
|
}
|
|
}
|