Make WordPress Core


Ignore:
Timestamp:
10/15/2025 05:38:25 AM (12 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/twentytwentyfive/functions.php

    r60424 r60934  
    4040add_action( 'after_setup_theme', 'twentytwentyfive_editor_style' );
    4141
    42 // Enqueues style.css on the front.
     42// Enqueues the theme stylesheet on the front.
    4343if ( ! function_exists( 'twentytwentyfive_enqueue_styles' ) ) :
    4444        /**
    45          * Enqueues style.css on the front.
     45         * Enqueues the theme stylesheet on the front.
    4646         *
    4747         * @since Twenty Twenty-Five 1.0
    … …  
    5050         */
    5151        function twentytwentyfive_enqueue_styles() {
     52                $suffix = SCRIPT_DEBUG ? '' : '.min';
     53                $src    = 'style' . $suffix . '.css';
     54
    5255                wp_enqueue_style(
    5356                        'twentytwentyfive-style',
    54                         get_parent_theme_file_uri( 'style.css' ),
     57                        get_parent_theme_file_uri( $src ),
    5558                        array(),
    5659                        wp_get_theme()->get( 'Version' )
Note: See TracChangeset for help on using the changeset viewer.