
Product
Announcing Socket Fix 2.0
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
vite-plugin-chunk-split
Advanced tools
English | 中文
A vite plugin for better chunk splitting.
// use npm
npm i vite-plugin-chunk-split -D
// use yarn
yarn add vite-plugin-chunk-split -D
// use pnpm
pnpm i vite-plugin-chunk-split -D
Then you can use it in vite.config.ts:
// vite.config.ts
import { chunkSplitPlugin } from 'vite-plugin-chunk-split';
{
plugins: [
// ...
chunkSplitPlugin()
]
}
type packageInfo = string | RegExp;
type Strategy =
// 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';
export type CustomSplitting = Record<string, packageInfo[]>;
export interface ChunkSplitOptions {
strategy?: Strategy;
customSplitting?: CustomSplitting;
}
You can use the options to customize your splitting strategy, for example:
// vite.config.ts
import { chunkSplitPlugin } from 'vite-plugin-chunk-split';
{
plugins: [
// ...
chunkSplitPlugin({
strategy: 'single-vendor',
customChunk: (args)=>{
// files into pages directory is export in single files
let { file, id, moduleId, root } = args;
if(file.startsWith('src/pages/')){
file = file.substring(4);
file = file.replace(/\.[^.$]+$/, '');
return file;
}
return null;
}
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.ts
import { 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/]
}
})
]
}
MIT
FAQs
A vite plugin for better chunk split
The npm package vite-plugin-chunk-split receives a total of 7,159 weekly downloads. As such, vite-plugin-chunk-split popularity was classified as popular.
We found that vite-plugin-chunk-split demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket Fix 2.0 brings targeted CVE remediation, smarter upgrade planning, and broader ecosystem support to help developers get to zero alerts.
Security News
Socket CEO Feross Aboukhadijeh joins Risky Business Weekly to unpack recent npm phishing attacks, their limited impact, and the risks if attackers get smarter.
Product
Socket’s new Tier 1 Reachability filters out up to 80% of irrelevant CVEs, so security teams can focus on the vulnerabilities that matter.