close
Skip to content

wp-build: Add --no-script-debug flag to skip unminified asset generation #75395

@kraftbj

Description

@kraftbj

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:

  1. Skips generating unminified assets entirely — no .js / .css counterparts to the .min.js / .min.css files, saving build time and disk space.
  2. Emits a build-time constant (has_debug_assets) in constants.php so the generated PHP registration templates know whether unminified files exist, rather than relying on runtime file_exists() checks.
  3. Updates the PHP registration templates to consult has_debug_assets before choosing the unminified path. When SCRIPT_DEBUG is true but has_debug_assets is false, the templates fall back to the minified file gracefully.

This affects the CLI, the build pipeline, and 4 PHP templates:

  • script-registration.php.template
  • module-registration.php.template
  • routes-registration.php.template
  • style-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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions