core-js-builder lets you produce a trimmed core-js bundle tailored to your exact feature set and target environments. Instead of shipping every polyfill, you include only the ones actually needed.
It accepts the same modules, exclude, and targets format as core-js-compat and uses Rollup internally to produce the output.
Installation
Usage
Full example
Minimal example
Options
modules
Which core-js features to include. Accepts a string, regex, or array of either. Uses the same format as core-js-compat modules.
Defaults to all core-js modules when omitted.
exclude
Modules to remove from the result after applying modules. Same format as modules.
targets
Optional. A browserslist query or a core-js-compat targets object. When provided, only modules actually needed by the target environments are included.
Omit to include all selected modules regardless of environment support.
summary
Optional. Controls how a summary of the bundle is reported.
true to enable all fields for that output:
format
Output format. Defaults to 'bundle'.
| Value | Description |
|---|---|
'bundle' | A self-contained IIFE suitable for <script> tags or direct browser use |
'cjs' | CommonJS — produces require() imports of individual modules rather than bundling them |
'esm' | ES modules — produces import statements of individual modules rather than bundling them |
When
format is 'cjs' or 'esm', the result is not bundled. It contains import/require statements pointing at the individual core-js module files, which must be resolvable in the target environment.filename
Optional. Path to write the output to. If omitted, the file is not written to disk and the bundle is only returned as a string.
TypeScript
When importingcore-js-builder from TypeScript, set esModuleInterop: true in your tsconfig.json:
import builder from 'core-js-builder') to work correctly.
How it works
Resolve modules
core-js-builder expands your modules and exclude inputs into a flat list of individual core-js module names using the same logic as core-js-compat.Filter by targets
If
targets is provided, the list is further filtered to only the modules that are actually missing in the specified environments (via core-js-compat).Bundle with Rollup
The filtered module list is passed to Rollup, which produces a single output file (for
bundle format) or a set of import statements (for cjs/esm format).When to use core-js-builder
Custom bundle for legacy environments
Generate a bundle containing only the polyfills needed for IE 9–11 or other specific legacy targets, keeping bundle size as small as possible.
CDN self-hosting
Produce a standalone IIFE bundle to host on your own CDN rather than depending on a third-party service.
Feature-gated polyfilling
Include only a specific namespace (e.g.,
core-js/actual) or a subset of proposals, excluding anything your codebase does not use.Build pipeline integration
Incorporate polyfill generation as a step in your CI/CD pipeline, regenerating the bundle whenever target configurations change.