Make WordPress Core


Ignore:
Timestamp:
10/15/2025 05:38:25 AM (6 months ago)
Author:
westonruter
Message:

Bundled Themes: Introduce stylesheet minification for core block themes.

This introduces a build process to provide minified stylesheets for the Twenty Twenty-Two and Twenty Twenty-Five themes. The built minified CSS is not committed to version control. When SCRIPT_DEBUG is disabled, the minified style.min.css file will be enqueued to improve performance, including reducing render-blocking resources as well as facilitating inlining. See #63007.

  • Stylesheets are minified via the new core cssmin:themes Grunt task, which is automatically run as part of build:css.
  • The same build process is added to the themes (via package.json and package-lock.json) with build and watch commands; the postcss and cssnano development dependencies are used to handle CSS minification.
  • The functions.php in each theme is updated to enqueue style.min.css unless SCRIPT_DEBUG is enabled, in which case style.css is enqueued.
  • A notice comment is added to style.css to warn against editing the stylesheet since the minified version will likely be served instead.
  • A new contributing.txt file is added to each theme to document the build process for developers.
  • The test-and-zip-default-themes GitHub workflow is updated to install npm dependencies and build the minified assets before packaging the themes.
  • New PHPUnit tests are added to verify version number consistency across style.css, readme.txt, package.json, and package-lock.json files in default themes.

Developed in https://github.com/WordPress/wordpress-develop/pull/10081.

Props b1ink0, westonruter, shyamgadde, jonsurrell, sabernhardt, jorbin, peterwilsoncc, poena.
Fixes #63012.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentytwentytwo/functions.php

    r60538 r60934  
    4646
    4747        $version_string = is_string( $theme_version ) ? $theme_version : false;
     48
     49        $suffix = SCRIPT_DEBUG ? '' : '.min';
     50        $src    = 'style' . $suffix . '.css';
     51
    4852        wp_register_style(
    4953            'twentytwentytwo-style',
    50             get_template_directory_uri() . '/style.css',
     54            get_parent_theme_file_uri( $src ),
    5155            array(),
    5256            $version_string
Note: See TracChangeset for help on using the changeset viewer.