What this thread does
Do first: run vite build with base matching the production mount path, then move an optional feature's static import behind its route or user action.
Short answer
As of November 2026, Vite 8.3.5 is this card's baseline, including chunk import-map fixes. Reduce unnecessary imports, defer optional features, then consider grouping. A new chunk name alone does not defer execution.
Choose / don't choose
- Optional route/action: choose
import('./exportReport')inside its action; don't leave another static import path to the same feature. For React, declarelazy(() => import('./pages/Reports'))at module scope and render only on the matching route; it requires a default export and a loading boundary (React lazy). - Necessary code on every route: remove unused dependencies or narrow imports; don't expect lazy loading to reduce code needed immediately.
- Manual grouping: choose only for a measured caching/loading need; don't group every dependency into one vendor chunk. Rolldown code splitting documents groups..
Not for: dependency optimizer failures; see vite-504-outdated-optimize-dep-rebuild-cache.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
base | Default /; use actual mount such as /foo/, full public URL, or ./ for relative embedded deployment | Current client build | shared options |
build.cssCodeSplit | true keeps async CSS with its chunks; default true for apps, false with build.lib | Current build | build options |
build.assetsInlineLimit | Default 4096 bytes; 0 disables inlining for app builds; library builds ignore it | Current build | build options |
build.chunkSizeWarningLimit | Default 500 kB uncompressed; increasing it only changes warning threshold | Current build | warning reference |
build.reportCompressedSize | Default true; gzip estimate, not compression of served responses | Current build | build options |
build.rolldownOptions.output.codeSplitting | Use deliberate groups only when automatic splitting misses an observed need | Current build | Rolldown |
Migration guide: object-form output.manualChunks is unsupported; its function form is deprecated in favor of codeSplitting.
Order of operations
1. Record initial transferred JS and total emitted JS separately. Inspect the largest modules and importers with the visualizer README and its package manifest. Resolve a compatible published package; keep its report out of deployment. 2. Replace the optional feature's static import with an action/route-triggered import(). Remove eager barrel/router paths. Matched files are lazy-loaded via dynamic import by default; { eager: true } removes that deferral. Variable imports must have a prefix of ./, ../ or # and a file extension and span only one filename level (features). 3. Import assets or use new URL('./img.png', import.meta.url).href inside browser modules. An analyzable template such as ./dir/${name}.png is transformed, but does not cover subdirectories. Arbitrary new URL(imagePath, import.meta.url) is left unchanged; this browser URL pattern cannot serve as an SSR asset resolver (assets). 4. Build, then use vite preview to exercise initial entry, direct lazy-route entry, refresh, back navigation, CSS and image loading under the real mount path. In browser Network, the optional feature should load only when requested and all emitted asset URLs should resolve. Preview is a local build inspection, not production hosting. 5. Remove bytes independently: Moment is in maintenance mode; inventory locale/time-zone and mutation behavior before replacement. Lodash offers modular builds; inspect retained helpers before assuming tree shaking failed. 6. Preserve old hashed assets through the client rollout window where possible. Set HTML Cache-Control: no-cache so revalidation discovers the current entry (production guide). Exercise an old open tab across a deployment and avoid an automatic reload loop.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
vite:preloadError (event) | Old client requests a chunk deleted by a later deployment | Inspect event.payload; event.preventDefault() suppresses the thrown error only when handling it; offer a bounded reload to current HTML, retain old assets where possible | production guide |
Some chunks are larger than 500 KiB after minification | A chunk exceeds a warning threshold; not itself a failed build | Inspect modules/importers, defer optional imports, remove unnecessary code; don't hide the symptom by increasing the limit | options, mehulsatardekar, July 29, 2022 |
In that discussion, superjose identifies highlight.js through a visualizer; a reply reports a production failure despite working locally. The Lodash question asks whether manual grouping puts the whole library into a chunk without allowing tree shaking. These reports do not establish a universal chunk recipe.
Missing
- No application graph or deployment mount is specified;
/foo/is an example, not a universalbase. - No build or performance measurements establish byte savings. Check host
Content-Encodingindependently of gzip size estimates.
Started from a post by @mehulsatardekar, packaged by the editor. Original post