Angular构建生成es5与es2015重复chunk问题咨询
Why You See Duplicate Chunks with
es5 and es2015 in Angular Builds, and What It Means for Bundle Size Hey there, let's break this down clearly—this isn't a bug, it's actually an intentional feature built into Angular to balance compatibility and performance.
What's Causing the "Duplicate" Chunks?
This is all thanks to differential loading, a feature introduced in Angular 8 that's enabled by default for production builds. Here's how it works:
- Angular generates two separate sets of bundle chunks:
- One set tagged with
es2015: Optimized for modern browsers that support ES2015+ syntax (like Chrome, Firefox, Edge post-2020). These chunks use native modern JS features (arrow functions,let/const, native classes) without extra transpilation bloat. - Another set tagged with
es5: Transpiled to ES5 syntax and includes necessary polyfills, designed for older browsers that don't support modern JS (like IE11, very old Safari versions).
- One set tagged with
- The "duplicate" label is just because they correspond to the same logical module, but compiled for different environments—they're not identical under the hood.
Does This Increase the Overall Bundle Size?
Let's split this into two key parts:
- Total build output size on disk: Yes, the combined size of both sets is larger than if you only built for one target. But this is a deliberate tradeoff to support both modern and legacy browsers.
- Size downloaded by end users: No, users won't download both sets. Angular automatically modifies your
index.htmlto include:<script type="module">tags for thees2015bundles (modern browsers will load these, ignoring the other set entirely)<script nomodule>tags for thees5bundles (only older browsers that don't support JS modules will load these)
- Bonus perk: The
es2015bundles are actually smaller than theires5counterparts, since they skip the transpilation overhead. Modern browser users get a lighter, faster-loading experience as a result.
Optional: Disable Differential Loading (If You Don't Need It)
If you're sure you don't need to support legacy browsers, you can turn this off:
- Open your
tsconfig.jsonand confirm"target": "es2015"(this is the default in newer Angular versions, but double-check) - Or, in
angular.json, under your build configuration, add"differentialLoading": falseto theoptionsobject.
内容的提问来源于stack exchange,提问作者chethankumar
相关产品推荐
相关产品推荐

