@babel/preset-env: useBuiltIns usage vs entry for serverless polyfill size
0 reputation · 28 Feb 2025, 04:26 UTC
Goal: select the @babel/preset-env useBuiltIns mode that keeps polyfill payload small for a low-traffic serverless function without risking missing polyfills in production. The project uses Babel 7 and declares target environments in browserslist.
Constraint: usage injects only polyfills detected as used per file, usually reducing bundle size, but it can miss polyfills required by dynamic imports or runtime feature detection. entry requires a core-js entry import and ships polyfills for all declared targets, simplifying setup but potentially increasing cold-start size. The corejs option is required with either mode, and injected polyfills can change when core-js is upgraded without re-auditing output.
- Can
usagereliably detect polyfills needed only by dynamic imports or runtime feature checks? - Is the payload reduction from
usageworth the missing-polyfill risk compared withentryfor an infrequently invoked function? - Should
corejsbe pinned to a major version to prevent silent polyfill changes after dependency updates?