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/.github/workflows/test-and-zip-default-themes.yml

    r60692 r60934  
    1515      - 'src/wp-content/themes/twentytwenty/**'
    1616      - 'src/wp-content/themes/twentytwentyone/**'
     17      - 'src/wp-content/themes/twentytwentytwo/**'
     18      - 'src/wp-content/themes/twentytwentyfive/**'
    1719      # Changes to this workflow file should always verify success.
    1820      - '.github/workflows/test-and-zip-default-themes.yml'
    … …  
    3032      - 'src/wp-content/themes/twentytwenty/**'
    3133      - 'src/wp-content/themes/twentytwentyone/**'
     34      - 'src/wp-content/themes/twentytwentytwo/**'
     35      - 'src/wp-content/themes/twentytwentyfive/**'
    3236      # Changes to this workflow file should always verify success.
    3337      - '.github/workflows/test-and-zip-default-themes.yml'
    … …  
    121125      matrix:
    122126        theme: [
     127            'twentytwentyfive',
     128            'twentytwentytwo',
    123129            'twentytwentyone',
    124130            'twentytwenty',
    … …  
    222228          persist-credentials: false
    223229
     230      - name: Set up Node.js for themes needing minification
     231        if: matrix.theme == 'twentytwentytwo' || matrix.theme == 'twentytwentyfive'
     232        uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
     233        with:
     234          node-version-file: '.nvmrc'
     235          cache: npm
     236          cache-dependency-path: src/wp-content/themes/${{ matrix.theme }}/package-lock.json
     237
     238      - name: Install npm dependencies
     239        if: matrix.theme == 'twentytwentytwo' || matrix.theme == 'twentytwentyfive'
     240        run: npm ci
     241        working-directory: src/wp-content/themes/${{ matrix.theme }}
     242
     243      - name: Build theme assets
     244        if: matrix.theme == 'twentytwentytwo' || matrix.theme == 'twentytwentyfive'
     245        run: npm run build
     246        working-directory: src/wp-content/themes/${{ matrix.theme }}
     247
    224248      - name: Upload theme ZIP as an artifact
    225249        uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
    226250        with:
    227251          name: ${{ matrix.theme }}
    228           path: src/wp-content/themes/${{ matrix.theme }}
     252          path: |
     253            src/wp-content/themes/${{ matrix.theme }}
     254            !src/wp-content/themes/${{ matrix.theme }}/node_modules
    229255          if-no-files-found: error
    230256          include-hidden-files: true
Note: See TracChangeset for help on using the changeset viewer.