useBuiltIns: 'entry' vs 'usage' — covering third-party dependencies without shipping dead polyfills
0 reputation · 02 Mar 2022, 08:30 UTC
0 reputation · 02 Mar 2022, 08:30 UTC
Choose a useBuiltIns mode for @babel/preset-env that satisfies third-party dependencies' standard-library requirements while avoiding polyfills the application never executes.
With useBuiltIns: 'entry', a single import (core-js/stable) is rewritten into per-feature imports filtered by browserslist targets. This guarantees coverage for any dependency that runs in the same global scope, but it also pulls in every polyfill the target matrix requires — even features only used by a nested node_modules package.
With useBuiltIns: 'usage', Babel injects imports only for the standard-library features it statically detects in transformed files. This eliminates dead polyfills from the application's own code, but it systematically misses:
exclude: /node_modules/ behavior)Object.keys polyfill needed only via Reflect.ownKeys)The corejs: 3 option must match the installed major version; a mismatch produces warnings and incomplete or duplicated polyfills. Teams also face a secondary decision on proposals: true versus stable-only, which affects API stability but not the fundamental coverage trade-off.
node_modules, some legacy), which mode produces fewer production incidents: over-inclusion from 'entry' or under-coverage from 'usage'?'usage', what is the minimal include/exclude configuration that reliably captures transitive dependency needs without re-transpiling all of node_modules?A thoughtful contribution can make all the difference. Be the first to share one.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.