Polyfills for WordPress Core packages not yet available in WordPress < 7.0.
This package conditionally registers @wordpress/* packages as both classic scripts (IIFE) and script modules (ESM) when they are not already provided by Core or Gutenberg.
It is intended to be used until WordPress 7.1 is released, at which point versions of WordPress < 7.0 will no longer be supported and this package will no longer be needed.
WordPress 7.0 introduces several new packages (@wordpress/boot, @wordpress/route, @wordpress/theme, etc.) that plugins built with @wordpress/build depend on. On older WordPress versions, these packages are missing or ship incomplete implementations — for example, wp-private-apis has an allowlist that rejects @wordpress/theme and @wordpress/route, and wp-notices lacks component exports that @wordpress/boot requires.
This package provides those missing packages so that plugins using @wordpress/build can work on WordPress versions before 7.0.
| Handle | Source package | Force-replaced on WP < 7.0? |
|---|---|---|
wp-notices |
@wordpress/notices |
Yes — missing component exports |
wp-private-apis |
@wordpress/private-apis |
Yes — incomplete allowlist |
wp-theme |
@wordpress/theme |
No — only registered if absent |
wp-views |
@wordpress/views |
No — only registered if absent |
| Module ID | Source package |
|---|---|
@wordpress/boot |
@wordpress/boot |
@wordpress/route |
@wordpress/route |
@wordpress/a11y |
@wordpress/a11y |
Script modules use "first-wins" semantics — if Core or Gutenberg already registered the module, the polyfill is silently ignored.
WP_Build_Polyfills::register()hooks intowp_default_scriptsat priority 20, after Core (priority 0) and Gutenberg (priority 10) have registered their scripts.- For each polyfill, it checks whether a built asset file exists (
build/scripts/*/index.asset.phporbuild/modules/*/index.asset.php). - For classic scripts, it checks whether the handle is already registered. Scripts marked as
forceare deregistered and re-registered with the polyfill version. Non-force scripts are skipped if already registered. - For script modules, it calls
wp_register_script_module(), which silently ignores duplicates.
Call register() early in your plugin, specifying a consumer name and the polyfills you need:
use Automattic\Jetpack\WP_Build_Polyfills\WP_Build_Polyfills;
WP_Build_Polyfills::register( 'my-plugin', array(
'wp-notices',
'wp-private-apis',
'@wordpress/boot',
'@wordpress/route',
) );Available handles are listed in WP_Build_Polyfills::SCRIPT_HANDLES and WP_Build_Polyfills::MODULE_IDS.
Multiple plugins can call register() — the hook is only added once, and all requested polyfills are merged. You can inspect which consumers requested which polyfills via WP_Build_Polyfills::get_consumers().
The version threshold for force-replacements can be overridden with a third parameter:
WP_Build_Polyfills::register( 'my-plugin', array( 'wp-notices' ), '7.1' );Packages that use @wordpress/build to generate pages get a hardcoded reference to build/modules/boot/index.min.asset.php in the generated page templates. This file provides the classic script dependencies and version hash needed to bootstrap the page.
When @wordpress/build stops bundling the boot module (as planned in upcoming Gutenberg changes), this asset file will no longer be generated. This package builds its own boot module asset file, and ships a bin script (provide-boot-asset-file) that copies it to the expected location in the consumer's build directory.
Consuming packages should add @automattic/jetpack-wp-build-polyfills as a devDependency and call the script after wp-build:
"build:boot-proxy": "provide-boot-asset-file"# Build polyfills (development)
pnpm run build
# Build polyfills (production)
pnpm run build-production
# Run PHP tests
composer run test-php