You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typepackageInfo=string|RegExp;typeStrategy=// split by default|'default'// all files will be together|'all-in-one'// unbundle for your source files,vite will generate one chunk for every file|'unbundle';exporttypeCustomSplitting=Record<string,packageInfo[]>;exportinterfaceChunkSplitOptions{strategy?: Strategy;customSplitting?: CustomSplitting;}
You can use the options to customize your splitting strategy, for example:
// vite.config.tsimport{chunkSplitPlugin}from'vite-plugin-chunk-split';{plugins: [// ...chunkSplitPlugin({strategy: 'single-vendor',customChunk: (args)=>{// files into pages directory is export in single fileslet{ file, id, moduleId, root }=args;if(file.startsWith('src/pages/')){file=file.substring(4);file=file.replace(/\.[^.$]+$/,'');returnfile;}returnnull;}customSplitting: {// `react` and `react-dom` will be bundled together in the `react-vendor` chunk (with their dependencies, such as object-assign)
'react-vendor': ['react', 'react-dom'],// Any file that includes `utils` in src dir will be bundled in the `utils` chunk 'utils': [/src\/utils/]
}})]}
By the way, you can achieve bundleless by the unbundle strategy:
// vite.config.tsimport{chunkSplitPlugin}from'vite-plugin-chunk-split';{plugins: [// ...chunkSplitPlugin({strategy: 'unbundle',customSplitting: {// All files in `src/container` will be merged together in `container` chunk'container': [/src\/container/]}})]}
License
MIT
About
A vite plugin for better chunk splitting. 一个简单易用的 Vite 拆包插件