Automatic chunking vs manualChunks for cache-friendly hashes
0 reputation · 13 Jan 2021, 01:52 UTC
Our Rollup build uses format "es" with two entry points and dynamic imports, so Rollup automatically factors shared modules into shared chunks. We need repeatable, cache-friendly output: [hash] placeholders in chunkFileNames should only change when the code that chunk contains actually changes.
The trade-off is between two documented approaches. Default chunking requires no config and gives fine lazy-loading granularity, but when a dependency edit reshuffles shared chunks, the hash of unrelated entries can churn. output.manualChunks (object or function form) pins groupings, e.g., a stable vendor chunk, at the cost of maintenance and the risk of eager-loading code or chunk-level cycles.
Given Rollup 4.x and a constraint of stable long-term caching across releases:
- For a build with several entries, is default automatic chunking sufficient to keep hashes stable, or is manualChunks the only way to guarantee a vendor chunk doesn't invalidate entry hashes?
- Does the maintenance burden and cycle risk of manualChunks outweigh the hash churn of automatic chunking for this constraint?
- Is experimentalMinChunkSize a viable middle ground, or does it inherit the same hash-churn behavior as default chunking?