Lesson 17 / 30
Polyfills and Core-js
Understand how polyfills fill gaps that transpilation can't cover.
The polyfill vs transpile distinction
Transpilation converts syntax. Polyfills add missing functions: Promise, Array.prototype.includes(), Object.assign(), etc. Both are needed for legacy browser support.
Core-js: the standard polyfill library
core-js is the most complete polyfill library. Babel can inject only the polyfills your code actually needs via @babel/preset-env with useBuiltIns.
Configuring polyfill injection
Use useBuiltIns: 'usage' to automatically inject only needed polyfills. Reduces bundle size compared to including all of core-js.
{
"presets": [
[
"@babel/preset-env",
{
"useBuiltIns": "usage",
"corejs": "3.32"
}
]
]
}