From db3a51ffec4e264d295aa0984ccf81edeb52b628 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Fri, 27 Feb 2026 11:31:32 +0700 Subject: [PATCH 01/12] Reduce VIPS library size in build output The VIPS library added ~30MB of unnecessary files to the build: source maps (~20MB) and duplicate unminified workers (~10MB) containing inlined WASM. This disables sourcemaps for script module builds, skips unminified builds for packages with wpWorkers, adds a SCRIPT_DEBUG fallback for missing unminified files, and excludes .map files from the plugin ZIP. --- bin/build-plugin-zip.sh | 3 +- packages/wp-build/lib/build.mjs | 54 +++++++++++-------- .../module-registration.php.template | 10 +++- 3 files changed, 42 insertions(+), 25 deletions(-) diff --git a/bin/build-plugin-zip.sh b/bin/build-plugin-zip.sh index d98cfa96669ac9..c363ffda920d3c 100755 --- a/bin/build-plugin-zip.sh +++ b/bin/build-plugin-zip.sh @@ -86,6 +86,7 @@ zip --recurse-paths --no-dir-entries \ build-module \ readme.txt \ changelog.txt \ - README.md + README.md \ + --exclude "build/modules/**/*.map" success "Done. You've built Gutenberg! 🎉 " diff --git a/packages/wp-build/lib/build.mjs b/packages/wp-build/lib/build.mjs index e7c7134e916785..241c521e77632e 100755 --- a/packages/wp-build/lib/build.mjs +++ b/packages/wp-build/lib/build.mjs @@ -559,7 +559,7 @@ async function bundlePackage( packageName, options = {} ) { `${ fileName }.min.js` ), bundle: true, - sourcemap: true, + sourcemap: false, format: 'esm', target, platform: 'browser', @@ -573,31 +573,39 @@ async function bundlePackage( packageName, options = {} ) { true // Generate asset file for minified build ), ], - } ), - esbuild.build( { - entryPoints: [ entryPoint ], - outfile: path.join( - rootBuildModuleDir, - `${ fileName }.js` - ), - bundle: true, - sourcemap: true, - format: 'esm', - target, - platform: 'browser', - minify: false, - define: getDefine( true ), - plugins: [ - wordpressExternalsPlugin( - `${ baseFileName }.min`, - 'esm', - [], - false // Skip asset file for non-minified build - ), - ], } ) ); + // Skip unminified builds for packages with wpWorkers. + // These packages contain inlined WASM where unminified + // output provides no debugging value and adds ~10MB. + if ( ! packageJson.wpWorkers ) { + builds.push( + esbuild.build( { + entryPoints: [ entryPoint ], + outfile: path.join( + rootBuildModuleDir, + `${ fileName }.js` + ), + bundle: true, + sourcemap: false, + format: 'esm', + target, + platform: 'browser', + minify: false, + define: getDefine( true ), + plugins: [ + wordpressExternalsPlugin( + `${ baseFileName }.min`, + 'esm', + [], + false // Skip asset file for non-minified build + ), + ], + } ) + ); + } + const scriptModuleId = exportName === '.' ? `@${ packageNamespace }/${ packageName }` diff --git a/packages/wp-build/templates/module-registration.php.template b/packages/wp-build/templates/module-registration.php.template index c9cc9ac3bad559..a2094cec1ced47 100644 --- a/packages/wp-build/templates/module-registration.php.template +++ b/packages/wp-build/templates/module-registration.php.template @@ -28,13 +28,21 @@ if ( ! function_exists( '{{PREFIX}}_register_script_modules' ) ) { $asset_path = $modules_dir . '/' . $module['asset']; $asset = file_exists( $asset_path ) ? require $asset_path : array(); + $module_extension = $extension; + if ( '.js' === $extension ) { + $unminified_path = $modules_dir . '/' . $module['path'] . '.js'; + if ( ! file_exists( $unminified_path ) ) { + $module_extension = '.min.js'; + } + } + // Deregister first to override any previously registered version // (e.g., Core's default modules when running as a plugin). wp_deregister_script_module( $module['id'] ); wp_register_script_module( $module['id'], - $base_url . $module['path'] . $extension, + $base_url . $module['path'] . $module_extension, $asset['module_dependencies'] ?? array(), $asset['version'] ?? false, array( From f7d31c89ef065cce3aa05d6ca15f7ad086adbb4d Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Fri, 27 Feb 2026 13:35:05 +0700 Subject: [PATCH 02/12] docblock cleanup --- packages/wp-build/lib/build.mjs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/packages/wp-build/lib/build.mjs b/packages/wp-build/lib/build.mjs index 241c521e77632e..923b9b9874d261 100755 --- a/packages/wp-build/lib/build.mjs +++ b/packages/wp-build/lib/build.mjs @@ -576,9 +576,8 @@ async function bundlePackage( packageName, options = {} ) { } ) ); - // Skip unminified builds for packages with wpWorkers. - // These packages contain inlined WASM where unminified - // output provides no debugging value and adds ~10MB. + // Skip unminified builds for packages with wpWorkers which contain inlined + // WASM providing little debugging value. if ( ! packageJson.wpWorkers ) { builds.push( esbuild.build( { From 89960726069fbe5590c628779980999f4a2f024f Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Fri, 27 Feb 2026 13:46:09 +0700 Subject: [PATCH 03/12] Scope VIPS build optimizations to avoid side effects The previous commit disabled sourcemaps and unminified builds for all module packages. This narrows the changes to only the vips package, which is the one that inlines large WASM binaries. --- bin/build-plugin-zip.sh | 3 +-- packages/wp-build/lib/build.mjs | 14 +++++++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/bin/build-plugin-zip.sh b/bin/build-plugin-zip.sh index c363ffda920d3c..d98cfa96669ac9 100755 --- a/bin/build-plugin-zip.sh +++ b/bin/build-plugin-zip.sh @@ -86,7 +86,6 @@ zip --recurse-paths --no-dir-entries \ build-module \ readme.txt \ changelog.txt \ - README.md \ - --exclude "build/modules/**/*.map" + README.md success "Done. You've built Gutenberg! 🎉 " diff --git a/packages/wp-build/lib/build.mjs b/packages/wp-build/lib/build.mjs index 923b9b9874d261..7e5e9c7478cfe8 100755 --- a/packages/wp-build/lib/build.mjs +++ b/packages/wp-build/lib/build.mjs @@ -551,6 +551,10 @@ async function bundlePackage( packageName, options = {} ) { const entryPoint = path.join( packageDir, exportPath ); const baseFileName = path.basename( fileName ); + // Skip sourcemaps and unminified builds for the vips package + // which inlines large WASM binaries. + const isVips = packageName === 'vips'; + builds.push( esbuild.build( { entryPoints: [ entryPoint ], @@ -559,7 +563,7 @@ async function bundlePackage( packageName, options = {} ) { `${ fileName }.min.js` ), bundle: true, - sourcemap: false, + sourcemap: ! isVips, format: 'esm', target, platform: 'browser', @@ -576,9 +580,9 @@ async function bundlePackage( packageName, options = {} ) { } ) ); - // Skip unminified builds for packages with wpWorkers which contain inlined - // WASM providing little debugging value. - if ( ! packageJson.wpWorkers ) { + // Also skip the unminified build for vips; the inlined WASM + // doubles the output size and offers little debugging value. + if ( ! isVips ) { builds.push( esbuild.build( { entryPoints: [ entryPoint ], @@ -587,7 +591,7 @@ async function bundlePackage( packageName, options = {} ) { `${ fileName }.js` ), bundle: true, - sourcemap: false, + sourcemap: true, format: 'esm', target, platform: 'browser', From 5973dba3ca374ac597c07645e15ce860802950f8 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Mon, 2 Mar 2026 11:55:09 +0700 Subject: [PATCH 04/12] Add wpScriptModuleMinifiedOnly package.json flag Replace the hardcoded vips package name check with a generic wpScriptModuleMinifiedOnly flag that any package can set in its package.json to skip sourcemaps and unminified builds. --- packages/vips/package.json | 1 + packages/wp-build/lib/build.mjs | 15 ++++++++------- packages/wp-build/lib/package-utils.mjs | 1 + 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/packages/vips/package.json b/packages/vips/package.json index 5b00d09f239375..278971fba0774f 100644 --- a/packages/vips/package.json +++ b/packages/vips/package.json @@ -41,6 +41,7 @@ }, "./package.json": "./package.json" }, + "wpScriptModuleMinifiedOnly": true, "wpWorkers": { "./worker": { "entry": "./src/worker.ts", diff --git a/packages/wp-build/lib/build.mjs b/packages/wp-build/lib/build.mjs index 7e5e9c7478cfe8..f1a96854ff4e04 100755 --- a/packages/wp-build/lib/build.mjs +++ b/packages/wp-build/lib/build.mjs @@ -551,9 +551,11 @@ async function bundlePackage( packageName, options = {} ) { const entryPoint = path.join( packageDir, exportPath ); const baseFileName = path.basename( fileName ); - // Skip sourcemaps and unminified builds for the vips package - // which inlines large WASM binaries. - const isVips = packageName === 'vips'; + // When wpScriptModuleMinifiedOnly is set, skip sourcemaps and + // unminified builds to reduce output size (e.g. for packages + // that inline large WASM binaries). + const minifiedOnly = + packageJson.wpScriptModuleMinifiedOnly === true; builds.push( esbuild.build( { @@ -563,7 +565,7 @@ async function bundlePackage( packageName, options = {} ) { `${ fileName }.min.js` ), bundle: true, - sourcemap: ! isVips, + sourcemap: ! minifiedOnly, format: 'esm', target, platform: 'browser', @@ -580,9 +582,8 @@ async function bundlePackage( packageName, options = {} ) { } ) ); - // Also skip the unminified build for vips; the inlined WASM - // doubles the output size and offers little debugging value. - if ( ! isVips ) { + // Skip the unminified build when minifiedOnly is set. + if ( ! minifiedOnly ) { builds.push( esbuild.build( { entryPoints: [ entryPoint ], diff --git a/packages/wp-build/lib/package-utils.mjs b/packages/wp-build/lib/package-utils.mjs index 15b7dd04c5781a..755a9751e1969e 100644 --- a/packages/wp-build/lib/package-utils.mjs +++ b/packages/wp-build/lib/package-utils.mjs @@ -28,6 +28,7 @@ const packagePathCache = new Map(); * @property {Record} [peerDependencies] Peer dependencies. * @property {string[]} [wpScript] WordPress script handles for dependency extraction. * @property {Record} [wpScriptModuleExports] WordPress script module exports. + * @property {boolean} [wpScriptModuleMinifiedOnly] Only output minified script module builds (skip sourcemaps and unminified .js). * @property {Object} [sideEffects] Side effects configuration for tree shaking. * @property {string} [publishConfig] NPM publish configuration. * @property {Record} [scripts] NPM scripts. From f01cb586f9aef4d18af3a019ab9370f964e1dc7d Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Mon, 2 Mar 2026 12:21:51 +0700 Subject: [PATCH 05/12] Fix JSDoc line alignment in package-utils.mjs Co-Authored-By: Claude Opus 4.6 --- packages/wp-build/lib/package-utils.mjs | 38 ++++++++++++------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/wp-build/lib/package-utils.mjs b/packages/wp-build/lib/package-utils.mjs index 755a9751e1969e..ae107d76ee1fa6 100644 --- a/packages/wp-build/lib/package-utils.mjs +++ b/packages/wp-build/lib/package-utils.mjs @@ -15,26 +15,26 @@ const packagePathCache = new Map(); /** * @typedef {Object} PackageJson * - * @property {string} name Package name. - * @property {string} version Package version. - * @property {string} [description] Package description. - * @property {string} [author] Package author. - * @property {string} [license] Package license. - * @property {string} [main] Main entry point. - * @property {string} [module] ES module entry point. - * @property {string} [react-native] React Native entry point. - * @property {Record} [dependencies] Runtime dependencies. - * @property {Record} [devDependencies] Development dependencies. - * @property {Record} [peerDependencies] Peer dependencies. - * @property {string[]} [wpScript] WordPress script handles for dependency extraction. - * @property {Record} [wpScriptModuleExports] WordPress script module exports. + * @property {string} name Package name. + * @property {string} version Package version. + * @property {string} [description] Package description. + * @property {string} [author] Package author. + * @property {string} [license] Package license. + * @property {string} [main] Main entry point. + * @property {string} [module] ES module entry point. + * @property {string} [react-native] React Native entry point. + * @property {Record} [dependencies] Runtime dependencies. + * @property {Record} [devDependencies] Development dependencies. + * @property {Record} [peerDependencies] Peer dependencies. + * @property {string[]} [wpScript] WordPress script handles for dependency extraction. + * @property {Record} [wpScriptModuleExports] WordPress script module exports. * @property {boolean} [wpScriptModuleMinifiedOnly] Only output minified script module builds (skip sourcemaps and unminified .js). - * @property {Object} [sideEffects] Side effects configuration for tree shaking. - * @property {string} [publishConfig] NPM publish configuration. - * @property {Record} [scripts] NPM scripts. - * @property {string[]} [files] Files to include in package. - * @property {string} [repository] Repository URL. - * @property {string[]} [keywords] Package keywords. + * @property {Object} [sideEffects] Side effects configuration for tree shaking. + * @property {string} [publishConfig] NPM publish configuration. + * @property {Record} [scripts] NPM scripts. + * @property {string[]} [files] Files to include in package. + * @property {string} [repository] Repository URL. + * @property {string[]} [keywords] Package keywords. */ // Create a new type that extends PackageJson with an optional "route" property From 4b5c3f5c87775ddc1d9f2cc77693e292f2620d10 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Mon, 2 Mar 2026 19:37:01 +0700 Subject: [PATCH 06/12] Propagate minifiedOnly flag to PHP module registry The previous commit added wpScriptModuleMinifiedOnly to package.json but didn't pass the flag through to the PHP registry data. Without the minified_only entry in the registry, the PHP template couldn't override the .js extension when SCRIPT_DEBUG is on, causing module resolution failures for packages that only ship .min.js files. --- packages/wp-build/lib/build.mjs | 20 +++++++++++-------- .../module-registration.php.template | 10 +++++----- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/packages/wp-build/lib/build.mjs b/packages/wp-build/lib/build.mjs index f1a96854ff4e04..824ac80ec42c54 100755 --- a/packages/wp-build/lib/build.mjs +++ b/packages/wp-build/lib/build.mjs @@ -619,6 +619,7 @@ async function bundlePackage( packageName, options = {} ) { id: scriptModuleId, path: `${ packageName }/${ fileName }`, asset: `${ packageName }/${ fileName }.min.asset.php`, + minifiedOnly, } ); } } @@ -875,14 +876,17 @@ async function generateModuleRegistrationPhp( modules, replacements ) { // Generate modules array for registry const modulesArray = modules - .map( - ( module ) => - `\tarray(\n` + - `\t\t'id' => '${ module.id }',\n` + - `\t\t'path' => '${ module.path }',\n` + - `\t\t'asset' => '${ module.asset }',\n` + - `\t),` - ) + .map( ( module ) => { + const lines = [ + `\t\t'id' => '${ module.id }'`, + `\t\t'path' => '${ module.path }'`, + `\t\t'asset' => '${ module.asset }'`, + ]; + if ( module.minifiedOnly ) { + lines.push( `\t\t'minified_only' => true` ); + } + return `\tarray(\n${ lines.join( ',\n' ) },\n\t),`; + } ) .join( '\n' ); await Promise.all( [ diff --git a/packages/wp-build/templates/module-registration.php.template b/packages/wp-build/templates/module-registration.php.template index a2094cec1ced47..7ca6070da6f189 100644 --- a/packages/wp-build/templates/module-registration.php.template +++ b/packages/wp-build/templates/module-registration.php.template @@ -28,12 +28,12 @@ if ( ! function_exists( '{{PREFIX}}_register_script_modules' ) ) { $asset_path = $modules_dir . '/' . $module['asset']; $asset = file_exists( $asset_path ) ? require $asset_path : array(); + // Modules marked as minified_only (e.g. packages that inline large + // WASM binaries) only ship a .min.js file. Always use .min.js for + // these modules regardless of the SCRIPT_DEBUG setting. $module_extension = $extension; - if ( '.js' === $extension ) { - $unminified_path = $modules_dir . '/' . $module['path'] . '.js'; - if ( ! file_exists( $unminified_path ) ) { - $module_extension = '.min.js'; - } + if ( '.js' === $extension && ! empty( $module['minified_only'] ) ) { + $module_extension = '.min.js'; } // Deregister first to override any previously registered version From 8f67d0d21ad3dcba34944c99cd902b0f0c50dbd6 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Tue, 3 Mar 2026 11:09:30 +0700 Subject: [PATCH 07/12] Rename wpScriptModuleMinifiedOnly to wpScriptDebugSupport Broadens the flag to cover all build outputs (scripts, script modules, and styles) instead of just script modules. When set to false, skips unminified builds and sourcemaps for all output types. Adds file_exists fallbacks in script and style PHP templates so SCRIPT_DEBUG gracefully falls back to minified files when unminified versions don't exist. --- packages/vips/package.json | 2 +- packages/wp-build/lib/build.mjs | 71 +++++++++++-------- packages/wp-build/lib/package-utils.mjs | 2 +- .../script-registration.php.template | 10 ++- .../templates/style-registration.php.template | 12 +++- 5 files changed, 64 insertions(+), 33 deletions(-) diff --git a/packages/vips/package.json b/packages/vips/package.json index 278971fba0774f..fe6bbf6e5b5b26 100644 --- a/packages/vips/package.json +++ b/packages/vips/package.json @@ -41,7 +41,7 @@ }, "./package.json": "./package.json" }, - "wpScriptModuleMinifiedOnly": true, + "wpScriptDebugSupport": false, "wpWorkers": { "./worker": { "entry": "./src/worker.ts", diff --git a/packages/wp-build/lib/build.mjs b/packages/wp-build/lib/build.mjs index 824ac80ec42c54..ecf7ac80323650 100755 --- a/packages/wp-build/lib/build.mjs +++ b/packages/wp-build/lib/build.mjs @@ -460,6 +460,11 @@ async function bundlePackage( packageName, options = {} ) { const outputDir = path.join( BUILD_DIR, 'scripts', packageName ); const target = browserslistToEsbuild(); + // When wpScriptDebugSupport is false, skip sourcemaps and + // unminified builds to reduce output size. + const skipDebugBuilds = + packageJson.wpScriptDebugSupport === false; + // Check if package matches the namespace and should expose a global const packageFullName = packageJson.name; const matchesNamespace = packageFullName.startsWith( @@ -474,7 +479,7 @@ async function bundlePackage( packageName, options = {} ) { const baseConfig = { entryPoints: [ entryPoint ], bundle: true, - sourcemap: true, + sourcemap: ! skipDebugBuilds, format: 'iife', target, platform: 'browser', @@ -505,24 +510,30 @@ async function bundlePackage( packageName, options = {} ) { true // Generate asset file for minified build ), ], - } ), - esbuild.build( { - ...baseConfig, - outfile: path.join( outputDir, 'index.js' ), - minify: false, - define: getDefine( true ), - plugins: [ - ...baseBundlePlugins, - wordpressExternalsPlugin( - 'index.min', - 'iife', - packageJson.wpScriptExtraDependencies || [], - false // Skip asset file for non-minified build - ), - ], } ) ); + // Skip the unminified build when debug support is disabled. + if ( ! skipDebugBuilds ) { + builds.push( + esbuild.build( { + ...baseConfig, + outfile: path.join( outputDir, 'index.js' ), + minify: false, + define: getDefine( true ), + plugins: [ + ...baseBundlePlugins, + wordpressExternalsPlugin( + 'index.min', + 'iife', + packageJson.wpScriptExtraDependencies || [], + false // Skip asset file for non-minified build + ), + ], + } ) + ); + } + builtScripts.push( { handle: `${ handlePrefix }-${ packageName }`, path: `${ packageName }/index`, @@ -551,11 +562,11 @@ async function bundlePackage( packageName, options = {} ) { const entryPoint = path.join( packageDir, exportPath ); const baseFileName = path.basename( fileName ); - // When wpScriptModuleMinifiedOnly is set, skip sourcemaps and + // When wpScriptDebugSupport is false, skip sourcemaps and // unminified builds to reduce output size (e.g. for packages // that inline large WASM binaries). - const minifiedOnly = - packageJson.wpScriptModuleMinifiedOnly === true; + const skipDebugBuilds = + packageJson.wpScriptDebugSupport === false; builds.push( esbuild.build( { @@ -565,7 +576,7 @@ async function bundlePackage( packageName, options = {} ) { `${ fileName }.min.js` ), bundle: true, - sourcemap: ! minifiedOnly, + sourcemap: ! skipDebugBuilds, format: 'esm', target, platform: 'browser', @@ -582,8 +593,8 @@ async function bundlePackage( packageName, options = {} ) { } ) ); - // Skip the unminified build when minifiedOnly is set. - if ( ! minifiedOnly ) { + // Skip the unminified build when debug support is disabled. + if ( ! skipDebugBuilds ) { builds.push( esbuild.build( { entryPoints: [ entryPoint ], @@ -646,18 +657,22 @@ async function bundlePackage( packageName, options = {} ) { // Generate minified path: style.css -> style.min.css, style-rtl.css -> style-rtl.min.css const minifiedPath = destPath.replace( /\.css$/, '.min.css' ); - // Always produce both versions (like JavaScript does): - // 1. Non-minified version (for SCRIPT_DEBUG=true) - // 2. Minified version (for SCRIPT_DEBUG=false) + // When wpScriptDebugSupport is false, skip the non-minified + // CSS version to reduce output size. + const skipDebugBuilds = + packageJson.wpScriptDebugSupport === false; + builds.push( ( async () => { await mkdir( destDir, { recursive: true } ); const content = await readFile( cssFile, 'utf8' ); - // Write non-minified version - await writeFile( destPath, content ); + // Write non-minified version (for SCRIPT_DEBUG=true) + if ( ! skipDebugBuilds ) { + await writeFile( destPath, content ); + } - // Write minified version + // Write minified version (for SCRIPT_DEBUG=false) const result = await postcss( [ cssnano( { preset: [ diff --git a/packages/wp-build/lib/package-utils.mjs b/packages/wp-build/lib/package-utils.mjs index ae107d76ee1fa6..acc4b71add747a 100644 --- a/packages/wp-build/lib/package-utils.mjs +++ b/packages/wp-build/lib/package-utils.mjs @@ -28,7 +28,7 @@ const packagePathCache = new Map(); * @property {Record} [peerDependencies] Peer dependencies. * @property {string[]} [wpScript] WordPress script handles for dependency extraction. * @property {Record} [wpScriptModuleExports] WordPress script module exports. - * @property {boolean} [wpScriptModuleMinifiedOnly] Only output minified script module builds (skip sourcemaps and unminified .js). + * @property {boolean} [wpScriptDebugSupport] When false, skip unminified builds and sourcemaps for all outputs (scripts, script modules, styles). * @property {Object} [sideEffects] Side effects configuration for tree shaking. * @property {string} [publishConfig] NPM publish configuration. * @property {Record} [scripts] NPM scripts. diff --git a/packages/wp-build/templates/script-registration.php.template b/packages/wp-build/templates/script-registration.php.template index 401bfb5d1eea46..eb4a6c2a4a3e52 100644 --- a/packages/wp-build/templates/script-registration.php.template +++ b/packages/wp-build/templates/script-registration.php.template @@ -74,10 +74,18 @@ if ( ! function_exists( '{{PREFIX}}_register_package_scripts' ) ) { $dependencies = $asset['dependencies'] ?? array(); $version = $asset['version'] ?? $default_version; + $script_extension = $extension; + if ( '.js' === $extension ) { + $unminified_path = $scripts_dir . '/' . $script_data['path'] . '.js'; + if ( ! file_exists( $unminified_path ) ) { + $script_extension = '.min.js'; + } + } + {{PREFIX}}_override_script( $scripts, $script_data['handle'], - $build_constants['build_url'] . 'scripts/' . $script_data['path'] . $extension, + $build_constants['build_url'] . 'scripts/' . $script_data['path'] . $script_extension, $dependencies, $version, true diff --git a/packages/wp-build/templates/style-registration.php.template b/packages/wp-build/templates/style-registration.php.template index 061fd0aa7fcf7c..222983039a652d 100644 --- a/packages/wp-build/templates/style-registration.php.template +++ b/packages/wp-build/templates/style-registration.php.template @@ -59,17 +59,25 @@ if ( ! function_exists( '{{PREFIX}}_register_package_styles' ) ) { $plugin_dir = dirname( __FILE__ ); foreach ( $styles_data as $style_data ) { + $style_suffix = $suffix; + if ( '' === $suffix ) { + $unminified_path = $styles_dir . '/' . $style_data['path'] . '.css'; + if ( ! file_exists( $unminified_path ) ) { + $style_suffix = '.min'; + } + } + {{PREFIX}}_override_style( $styles, $style_data['handle'], - $build_constants['build_url'] . 'styles/' . $style_data['path'] . $suffix . '.css', + $build_constants['build_url'] . 'styles/' . $style_data['path'] . $style_suffix . '.css', $style_data['dependencies'], $default_version ); // Enable RTL support (WordPress automatically loads -rtl.css variant) $styles->add_data( $style_data['handle'], 'rtl', 'replace' ); - $styles->add_data( $style_data['handle'], 'suffix', $suffix ); + $styles->add_data( $style_data['handle'], 'suffix', $style_suffix ); } } From 938d47c7f4bb633c24c5473c799aa7fc350f9750 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Tue, 3 Mar 2026 11:13:19 +0700 Subject: [PATCH 08/12] Remove minifiedOnly from module registry data The file_exists fallback in the PHP template handles missing unminified files generically, making the per-module minified_only flag in the registry unnecessary. --- packages/wp-build/lib/build.mjs | 4 ---- .../templates/module-registration.php.template | 10 +++++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/packages/wp-build/lib/build.mjs b/packages/wp-build/lib/build.mjs index ecf7ac80323650..e4a509774bd56f 100755 --- a/packages/wp-build/lib/build.mjs +++ b/packages/wp-build/lib/build.mjs @@ -630,7 +630,6 @@ async function bundlePackage( packageName, options = {} ) { id: scriptModuleId, path: `${ packageName }/${ fileName }`, asset: `${ packageName }/${ fileName }.min.asset.php`, - minifiedOnly, } ); } } @@ -897,9 +896,6 @@ async function generateModuleRegistrationPhp( modules, replacements ) { `\t\t'path' => '${ module.path }'`, `\t\t'asset' => '${ module.asset }'`, ]; - if ( module.minifiedOnly ) { - lines.push( `\t\t'minified_only' => true` ); - } return `\tarray(\n${ lines.join( ',\n' ) },\n\t),`; } ) .join( '\n' ); diff --git a/packages/wp-build/templates/module-registration.php.template b/packages/wp-build/templates/module-registration.php.template index 7ca6070da6f189..a2094cec1ced47 100644 --- a/packages/wp-build/templates/module-registration.php.template +++ b/packages/wp-build/templates/module-registration.php.template @@ -28,12 +28,12 @@ if ( ! function_exists( '{{PREFIX}}_register_script_modules' ) ) { $asset_path = $modules_dir . '/' . $module['asset']; $asset = file_exists( $asset_path ) ? require $asset_path : array(); - // Modules marked as minified_only (e.g. packages that inline large - // WASM binaries) only ship a .min.js file. Always use .min.js for - // these modules regardless of the SCRIPT_DEBUG setting. $module_extension = $extension; - if ( '.js' === $extension && ! empty( $module['minified_only'] ) ) { - $module_extension = '.min.js'; + if ( '.js' === $extension ) { + $unminified_path = $modules_dir . '/' . $module['path'] . '.js'; + if ( ! file_exists( $unminified_path ) ) { + $module_extension = '.min.js'; + } } // Deregister first to override any previously registered version From de8559a456f6944cf0afd9b569c182687a5b93f6 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Wed, 4 Mar 2026 12:54:32 +0700 Subject: [PATCH 09/12] Fix prettier and JSDoc lint errors in wp-build - Collapse multiline `skipDebugBuilds` assignments to single lines (prettier) - Re-align JSDoc @typedef/@property columns in package-utils.mjs Co-Authored-By: Claude Opus 4.6 --- packages/wp-build/lib/build.mjs | 9 ++---- packages/wp-build/lib/package-utils.mjs | 42 ++++++++++++------------- 2 files changed, 24 insertions(+), 27 deletions(-) diff --git a/packages/wp-build/lib/build.mjs b/packages/wp-build/lib/build.mjs index e4a509774bd56f..930a5ed44988e7 100755 --- a/packages/wp-build/lib/build.mjs +++ b/packages/wp-build/lib/build.mjs @@ -462,8 +462,7 @@ async function bundlePackage( packageName, options = {} ) { // When wpScriptDebugSupport is false, skip sourcemaps and // unminified builds to reduce output size. - const skipDebugBuilds = - packageJson.wpScriptDebugSupport === false; + const skipDebugBuilds = packageJson.wpScriptDebugSupport === false; // Check if package matches the namespace and should expose a global const packageFullName = packageJson.name; @@ -565,8 +564,7 @@ async function bundlePackage( packageName, options = {} ) { // When wpScriptDebugSupport is false, skip sourcemaps and // unminified builds to reduce output size (e.g. for packages // that inline large WASM binaries). - const skipDebugBuilds = - packageJson.wpScriptDebugSupport === false; + const skipDebugBuilds = packageJson.wpScriptDebugSupport === false; builds.push( esbuild.build( { @@ -658,8 +656,7 @@ async function bundlePackage( packageName, options = {} ) { // When wpScriptDebugSupport is false, skip the non-minified // CSS version to reduce output size. - const skipDebugBuilds = - packageJson.wpScriptDebugSupport === false; + const skipDebugBuilds = packageJson.wpScriptDebugSupport === false; builds.push( ( async () => { diff --git a/packages/wp-build/lib/package-utils.mjs b/packages/wp-build/lib/package-utils.mjs index acc4b71add747a..095f4f14e74843 100644 --- a/packages/wp-build/lib/package-utils.mjs +++ b/packages/wp-build/lib/package-utils.mjs @@ -13,28 +13,28 @@ const packageJsonCache = new Map(); const packagePathCache = new Map(); /** - * @typedef {Object} PackageJson + * @typedef {Object} PackageJson * - * @property {string} name Package name. - * @property {string} version Package version. - * @property {string} [description] Package description. - * @property {string} [author] Package author. - * @property {string} [license] Package license. - * @property {string} [main] Main entry point. - * @property {string} [module] ES module entry point. - * @property {string} [react-native] React Native entry point. - * @property {Record} [dependencies] Runtime dependencies. - * @property {Record} [devDependencies] Development dependencies. - * @property {Record} [peerDependencies] Peer dependencies. - * @property {string[]} [wpScript] WordPress script handles for dependency extraction. - * @property {Record} [wpScriptModuleExports] WordPress script module exports. - * @property {boolean} [wpScriptDebugSupport] When false, skip unminified builds and sourcemaps for all outputs (scripts, script modules, styles). - * @property {Object} [sideEffects] Side effects configuration for tree shaking. - * @property {string} [publishConfig] NPM publish configuration. - * @property {Record} [scripts] NPM scripts. - * @property {string[]} [files] Files to include in package. - * @property {string} [repository] Repository URL. - * @property {string[]} [keywords] Package keywords. + * @property {string} name Package name. + * @property {string} version Package version. + * @property {string} [description] Package description. + * @property {string} [author] Package author. + * @property {string} [license] Package license. + * @property {string} [main] Main entry point. + * @property {string} [module] ES module entry point. + * @property {string} [react-native] React Native entry point. + * @property {Record} [dependencies] Runtime dependencies. + * @property {Record} [devDependencies] Development dependencies. + * @property {Record} [peerDependencies] Peer dependencies. + * @property {string[]} [wpScript] WordPress script handles for dependency extraction. + * @property {Record} [wpScriptModuleExports] WordPress script module exports. + * @property {boolean} [wpScriptDebugSupport] When false, skip unminified builds and sourcemaps for all outputs (scripts, script modules, styles). + * @property {Object} [sideEffects] Side effects configuration for tree shaking. + * @property {string} [publishConfig] NPM publish configuration. + * @property {Record} [scripts] NPM scripts. + * @property {string[]} [files] Files to include in package. + * @property {string} [repository] Repository URL. + * @property {string[]} [keywords] Package keywords. */ // Create a new type that extends PackageJson with an optional "route" property From 339d5f5575df57993dd312413d321372c014f4f7 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Mon, 23 Mar 2026 11:09:29 -0700 Subject: [PATCH 10/12] Revert unrelated whitespace change in package-utils.mjs Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/wp-build/lib/package-utils.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wp-build/lib/package-utils.mjs b/packages/wp-build/lib/package-utils.mjs index 96630589b3c93f..15b7dd04c5781a 100644 --- a/packages/wp-build/lib/package-utils.mjs +++ b/packages/wp-build/lib/package-utils.mjs @@ -13,7 +13,7 @@ const packageJsonCache = new Map(); const packagePathCache = new Map(); /** - * @typedef {Object} PackageJson + * @typedef {Object} PackageJson * * @property {string} name Package name. * @property {string} version Package version. From 501d1f9cfa4c5f3394673b3620feb7cf9dc61d65 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Mon, 23 Mar 2026 11:11:50 -0700 Subject: [PATCH 11/12] Remove unrelated comment and formatting changes from merge Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/wp-build/lib/build.mjs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/wp-build/lib/build.mjs b/packages/wp-build/lib/build.mjs index 5f2f35d12454cd..c6a856f5240f7d 100755 --- a/packages/wp-build/lib/build.mjs +++ b/packages/wp-build/lib/build.mjs @@ -546,10 +546,7 @@ async function bundlePackage( packageName, options = {} ) { true // Generate asset file for minified build ), ], - } ) - ); - - builds.push( + } ), esbuild.build( { ...baseConfig, outfile: path.join( outputDir, 'index.js' ), @@ -692,15 +689,18 @@ async function bundlePackage( packageName, options = {} ) { // Generate minified path: style.css -> style.min.css, style-rtl.css -> style-rtl.min.css const minifiedPath = destPath.replace( /\.css$/, '.min.css' ); + // Always produce both versions (like JavaScript does): + // 1. Non-minified version (for SCRIPT_DEBUG=true) + // 2. Minified version (for SCRIPT_DEBUG=false) builds.push( ( async () => { await mkdir( destDir, { recursive: true } ); const content = await readFile( cssFile, 'utf8' ); - // Write non-minified version (for SCRIPT_DEBUG=true) + // Write non-minified version await writeFile( destPath, content ); - // Write minified version (for SCRIPT_DEBUG=false) + // Write minified version const result = await postcss( [ cssnano( { preset: [ From 43735c6d5fb50fe0c3ef5ed342b0d7a774624a31 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Mon, 23 Mar 2026 11:13:49 -0700 Subject: [PATCH 12/12] Remove hardcoded size from comment Co-Authored-By: Claude Opus 4.6 (1M context) --- packages/wp-build/lib/build.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/wp-build/lib/build.mjs b/packages/wp-build/lib/build.mjs index c6a856f5240f7d..4c578d3ab4da43 100755 --- a/packages/wp-build/lib/build.mjs +++ b/packages/wp-build/lib/build.mjs @@ -593,7 +593,7 @@ async function bundlePackage( packageName, options = {} ) { const baseFileName = path.basename( fileName ); // Skip non-minified build and sourcemaps for WASM-inlined workers - // (e.g., vips). These are ~13MB of base64-encoded WASM with no + // (e.g., vips). These are mostly base64-encoded WASM with no // debugging value over the minified version. const isWasmWorker = packageJson.wpWorkers &&