Dependency Extraction Webpack Plugin: Externalize script modules as import() and emit module_dependencies#76397
Conversation
…mport() and emit module_dependencies Packages like @wordpress/abilities and @wordpress/core-abilities are script modules (registered via wpScriptModuleExports) that don't expose window globals. The plugin currently treats all @wordpress/* packages as window-global scripts, which breaks at runtime. This adds these packages to the existing defaultRequestToExternalModule switch and makes non-module (IIFE) builds also consult that function via a try-catch bridge. Script module externals are detected in processModule via m.externalType === 'import' and emitted as module_dependencies in the asset file, matching the format WordPress PHP expects.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: 0 B Total Size: 6.89 MB ℹ️ View Unchanged
|
|
Flaky tests detected in 28eac5d. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22956287715
|
Summary
FIxes: #75196
Packages like
@wordpress/abilitiesand@wordpress/core-abilitiesare script modules (registered viawpScriptModuleExports) that don't exposewindowglobals. The webpack dependency extraction plugin currently treats all@wordpress/*packages as window-global scripts, which causes:window.wp.abilities(doesn't exist at runtime)wp-abilitiesindependenciesinstead ofmodule_dependenciesin the asset fileThis PR adds these packages to the existing
defaultRequestToExternalModuleswitch (alongside@wordpress/a11yand@wordpress/interactivity-router) and makes non-module (IIFE) builds also consult that function. Script module externals are detected inprocessModuleviam.externalType === 'import'and emitted asmodule_dependenciesin the asset file, matching the format WordPress PHP expects.Changes
util.js— 2 lines: add@wordpress/abilitiesand@wordpress/core-abilitiesto the existingdefaultRequestToExternalModuleswitchindex.js— 3 changes:defaultRequestToExternalModulefirst (try-catch), fall through todefaultRequestToExternalfor regular scriptsprocessModule: detect import-type externals viam.externalType === 'import', route to separatechunkScriptModuleStaticDeps/chunkScriptModuleDynamicDepssetsmodule_dependenciesarray with static/dynamic entriesTest plan
npm install && npm run build. Check out https://github.com/jonathanbossenger/wp-ai-client-demo/tree/debug-wp-build-2 (branch debug-wp-build-2 ).