-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Description
What problem does this address?
wp-build generates both minified (.min.js) and unminified (.js) assets for every entry point. The unminified copies exist solely for SCRIPT_DEBUG — in normal operation, 100% of them go unused. For plugins shipping via WordPress.org, this doubles (or more) the JavaScript footprint of the build/ directory.
As a concrete example: one project's build/ directory ships ~2.7 MB of unminified JS alongside ~1.2 MB of minified equivalents. The unminified files account for ~61,000 lines of code that serve no purpose in production.
The generated PHP registration templates also assume unminified files are always present on disk:
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';When plugin authors exclude unminified files from their distributions (the natural fix for the size problem), SCRIPT_DEBUG = true causes registered script URLs to point to non-existent files, breaking functionality.
What is your proposed solution?
Add a --no-script-debug flag to wp-build that:
- Skips generating unminified assets entirely — no
.js/.csscounterparts to the.min.js/.min.cssfiles, saving build time and disk space. - Emits a build-time constant (
has_debug_assets) inconstants.phpso the generated PHP registration templates know whether unminified files exist, rather than relying on runtimefile_exists()checks. - Updates the PHP registration templates to consult
has_debug_assetsbefore choosing the unminified path. WhenSCRIPT_DEBUGis true buthas_debug_assetsis false, the templates fall back to the minified file gracefully.
This affects the CLI, the build pipeline, and 4 PHP templates:
script-registration.php.templatemodule-registration.php.templateroutes-registration.php.templatestyle-registration.php.template
The pattern in each template becomes:
$extension = '.min.js';
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG && $build_constants['has_debug_assets'] ) {
$extension = '.js';
}Without --no-script-debug, behavior is unchanged — both minified and unminified assets are generated and has_debug_assets is true. With --no-script-debug, only minified assets are generated, has_debug_assets is false, and SCRIPT_DEBUG falls back gracefully.