rollup-plugin-wp-resolve

raw JSON →
1.0.9 verified Mon Apr 27 auth: no javascript

A Rollup plugin that externalizes WordPress and Gutenberg dependencies, converting imports like '@wordpress/components' to global 'wp.*' globals (e.g., 'wp.components.ToggleControl'). Works with Rollup >=1.0.0. Inspired by WordPress dependency-extraction-webpack-plugin, it automatically handles @wordpress/* packages and common bundled libraries (jQuery, lodash, moment, React, ReactDOM). Avoids issues with camelCase conversions since v1.0.8. Stable at v1.0.9 but no recent updates; does not generate PHP dependency files for block registration.

error Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported.
cause Using CommonJS require() on an ESM-only package.
fix
Use import statement or configure Node.js to support ESM.
error TypeError: wpResolve is not a function
cause Using named import { wpResolve } instead of default import wpResolve.
fix
Change to: import wpResolve from 'rollup-plugin-wp-resolve';
error Unresolved import: @wordpress/... (missing global variable wp...)
cause Global 'wp' object not available at runtime because WordPress script enqueuing is missing.
fix
Ensure WordPress backend enqueues necessary scripts (wp-editor, wp-components, etc.) via wp_enqueue_script or register_block_type.
deprecated Package has not been updated since 2020; may not support latest Rollup versions.
fix Consider using @wordpress/dependency-extraction-webpack-plugin with webpack or migrating to a maintained alternative.
breaking Versions < 1.0.8 had a camelCasing bug that mapped 'wp.i18n' to 'wp.i18N' for certain imports.
fix Upgrade to >=1.0.8
gotcha Does not generate PHP files for block registration; only externalizes dependencies in the Rollup output.
fix Manually add wp_deregister_script / wp_register_script calls, or use dependency-extraction-webpack-plugin if PHP output is needed.
gotcha Only converts known @wordpress/* packages and a limited set of third-party libraries (jQuery, lodash, moment, React, ReactDOM).
fix Use the 'include' or 'exclude' options if available, but the plugin has no such configuration. Extend by forking or using other tools.
npm install rollup-plugin-wp-resolve
yarn add rollup-plugin-wp-resolve
pnpm add rollup-plugin-wp-resolve

Basic Rollup configuration using wpResolve to externalize WordPress dependencies to global wp.* variables.

import wpResolve from 'rollup-plugin-wp-resolve';

export default {
  input: 'src/index.js',
  output: {
    dir: 'output',
    format: 'iife'
  },
  plugins: [wpResolve()]
};