/rstack:rspack-split-chunksfrom rstack
Diagnoses and tunes Rspack optimization.splitChunks configuration for duplicate modules, oversized chunks, cache group issues, and route over-fetching.
Ships in rstack. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Use this skill when the task is to recommend, review, or debug optimization.splitChunks. If you are using ESM library, it's not the same algorithm of this skill.
chunks: "async", but for most production web apps the best starting point is:optimization: {
splitChunks: {
chunks: "all",
},
}
name as a graph-shaping option, not a cosmetic naming option.splitChunks to reason about JavaScript execution order or tree shaking. For JS, chunk loading/execution order is preserved by the runtime dependency graph, and tree shaking is decided elsewhere.Read references/repo-behavior.md when you need the source-backed rationale.
First identify which problem the user actually has:
splitChunks affects runtime execution orderDo not optimize all of these at once. Pick the primary goal and keep the rest as constraints.
Unless the user already has a measured problem that requires custom grouping, prefer:
optimization: {
splitChunks: {
chunks: "all",
},
}
Why:
If the existing config disables default or defaultVendors, assume that is suspicious until proven necessary.
Check these first:
namecacheGroups.*.nameenforce: truedefault / defaultVendorstest: /node_modules/ rules combined with a single global nameusedExports: falseminSizemaxSize combined with manual global namesname correctlyUse this rule:
name: splitChunks can keep different chunk combinations separate.name: matching modules are merged into the same named split chunk candidate.That means a fixed name: "vendors" or name: "common" is often the real reason a page starts fetching modules from unrelated dependency chains.
Prefer these alternatives before adding name:
name unsetidHint if the goal is filename identity, not grouping identitytest so the cache group is smallermaxSize to subdivide a big chunk instead of forcing a global nameUse a fixed name only when the user explicitly wants one shared asset across multiple entries/routes and accepts the extra coupling.
Rspack's built-in production-oriented behavior depends heavily on these two groups:
default: extracts modules shared by at least 2 chunks and reuses existing chunksdefaultVendors: extracts node_modules modules and reuses existing chunksThese defaults are usually the best balance between dedupe and "only fetch what this page needs".
If you customize cacheGroups, do not casually replace these with one manually named vendor bucket.
chunks: "all" without fear of breaking execution orderWhen a module group is split out, Rspack connects the new chunk back to the original chunk groups. That preserves JavaScript loading semantics.
So:
splitChunks changes chunk topologymaxSize as a refinement toolUse maxSize, maxAsyncSize, or maxInitialSize when the problem is "this shared chunk is too large", not when the problem is "I need a stable vendor chunk name".
Important behavior:
maxSize runs after a chunk already existsThis is usually safer than forcing one giant named vendor chunk, because it keeps chunk graph semantics while subdividing hot spots.
usedExports deliberatelyIf the user has multiple runtimes/entries and wants leaner shared chunks per runtime, prefer keeping usedExports enabled.
If they set usedExports: false, expect broader sharing and potentially larger common chunks.
This is still not tree shaking. It only changes how splitChunks groups modules across runtimes.
enforce: true as an escape hatchenforce: true bypasses several normal guardrails. Use it only when the user intentionally wants a split regardless of minSize, minChunks, and request limits.
If a config looks aggressive and hard to explain, check enforce before changing anything else.
Recommend:
optimization: {
splitChunks: {
chunks: "all",
},
}
Avoid:
defaultdefaultVendorsname before measuring a real problemRecommend:
namechunks: "all" if dedupe across initial chunks is still desiredAvoid:
cacheGroups: {
vendors: {
test: /[\\/]node_modules[\\/]/,
chunks: "all",
name: "vendors",
enforce: true
}
}
That pattern often creates one over-shared chunk that many pages must fetch.
Recommend:
name unsetidHintchunkIds: "deterministic" or other stable id strategies elsewhere in the configUse a fixed name only if the user explicitly prefers cache reuse over route isolation.
Recommend:
optimization: {
splitChunks: {
chunks: "all",
maxSize: 200000,
},
}
Then tune:
maxAsyncSize when async chunks are the pain pointmaxInitialSize when first-load pressure matters morehidePathInfo if generated part names should not leak path structureRecommend a named chunk only when the user says something like:
Even then, call out the tradeoff explicitly:
When reviewing a user's config, explicitly answer:
chunks: "all" a better baseline than the current config?name accidentally turn multiple candidates into one forced shared chunk?default or defaultVendors disabled without a strong reason?idHint satisfy the naming goal without changing grouping?maxSize a better fit than a broad manual vendor/common bucket?When the task includes diagnosis, ask for or generate stats that expose chunk relations:
stats: {
chunks: true,
chunkRelations: true,
chunkOrigins: true,
entrypoints: true,
modules: false
}
Then compare:
nameCommon reasons:
minSizeminSizeReductionminChunkschunks / test / cacheGroups do not actually select the same chunk combinationIf the duplicate module is tiny, do not assume this is a bug. Rspack may intentionally keep it in place because splitting it out would create a worse chunk.
No.
splitChunks only changes chunk boundaries and dependency edgesNo.
sideEffects, usedExports, and dead-code eliminationsplitChunks runs later and only reorganizes already-selected modules into chunkssplitChunks.usedExports is only a grouping hint for runtime-specific chunk combinations; it is not tree shaking itselfYes, potentially.
mini-css-extract-plugin or experiments.css can observe changed final CSS order after splitChunks rewrites chunk groupsSee web-infra-dev discussion #12.
chunks: \"all\", keep the default cache groups, and remove name unless you intentionally want forced sharing."name is not just a filename hint in Rspack splitChunks; it changes grouping behavior."splitChunks does not control JS execution order or tree shaking; it only changes chunk topology."splitChunks can affect CSS order in extracted-CSS scenarios, so treat CSS as a separate caveat."maxSize is the safer tool when the problem is one chunk being too large."What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub rstackjs/agent-skills --plugin rstack23 skills in this plugin
/migrate-to-rsbuildMigrate webpack, Vite, create-react-app (CRA/CRACO), or Vue CLI projects to Rsbuild./migrate-to-rslibMigrate tsc or tsup library projects to Rslib./migrate-to-rslintMigrate ESLint flat config or Oxlint to Rslint, preserving rule options, file scopes, and plugins while updating lint scripts, editor settings, and inline directives./migrate-to-rstestMigrate Jest, Vitest, or Playwright Test to Rstest while preserving test discovery, assertions, mocks, snapshots, and coverage.Other plugins' skills for the same job