Skip to content

Commit b56b386

Browse files
committed
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 #10081. Props b1ink0, westonruter, shyamgadde, jonsurrell, sabernhardt, jorbin, peterwilsoncc, poena. Fixes #63012. git-svn-id: https://develop.svn.wordpress.org/trunk@60934 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 7447c82 commit b56b386

File tree

15 files changed

+3703
-13
lines changed

15 files changed

+3703
-13
lines changed

.github/dependabot.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,28 @@ updates:
129129
- "underscore"
130130

131131
# Monitor npm dependencies within default themes.
132+
- package-ecosystem: "npm"
133+
directory: "/src/wp-content/themes/twentytwentyfive"
134+
schedule:
135+
interval: "weekly"
136+
open-pull-requests-limit: 20
137+
groups:
138+
twentytwentyfive-css:
139+
patterns:
140+
- "**browserslist*"
141+
- "*css*"
142+
143+
- package-ecosystem: "npm"
144+
directory: "/src/wp-content/themes/twentytwentytwo"
145+
schedule:
146+
interval: "weekly"
147+
open-pull-requests-limit: 20
148+
groups:
149+
twentytwentytwo-css:
150+
patterns:
151+
- "**browserslist*"
152+
- "*css*"
153+
132154
- package-ecosystem: "npm"
133155
directory: "/src/wp-content/themes/twentytwentyone"
134156
schedule:

.github/workflows/test-and-zip-default-themes.yml

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ on:
1414
- 'src/wp-content/themes/twentynineteen/**'
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'
1921
pull_request:
@@ -29,6 +31,8 @@ on:
2931
- 'src/wp-content/themes/twentynineteen/**'
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'
3438
workflow_dispatch:
@@ -120,6 +124,8 @@ jobs:
120124
fail-fast: false
121125
matrix:
122126
theme: [
127+
'twentytwentyfive',
128+
'twentytwentytwo',
123129
'twentytwentyone',
124130
'twentytwenty',
125131
'twentynineteen',
@@ -221,11 +227,31 @@ jobs:
221227
show-progress: ${{ runner.debug == '1' && 'true' || 'false' }}
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
231257

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ wp-tests-config.php
8888
/src/wp-content/themes/twentynineteen/node_modules
8989
/src/wp-content/themes/twentytwentyone/node_modules
9090
/src/wp-content/themes/twentytwenty/node_modules
91+
/src/wp-content/themes/twentytwentytwo/node_modules
92+
/src/wp-content/themes/twentytwentyfive/node_modules
93+
94+
# Minified files in bundled themes
95+
/src/wp-content/themes/twentytwentytwo/*.min.css
96+
/src/wp-content/themes/twentytwentyfive/*.min.css
9197

9298
# Operating system specific files
9399
.DS_Store

Gruntfile.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,16 @@ module.exports = function(grunt) {
567567
src: [
568568
'wp-admin/css/colors/*/*.css'
569569
]
570+
},
571+
themes: {
572+
expand: true,
573+
cwd: WORKING_DIR,
574+
dest: WORKING_DIR,
575+
ext: '.min.css',
576+
src: [
577+
'wp-content/themes/twentytwentytwo/style.css',
578+
'wp-content/themes/twentytwentyfive/style.css',
579+
]
570580
}
571581
},
572582
rtlcss: {
@@ -1591,6 +1601,7 @@ module.exports = function(grunt) {
15911601
'rtl',
15921602
'cssmin:rtl',
15931603
'cssmin:colors',
1604+
'cssmin:themes',
15941605
'usebanner'
15951606
] );
15961607

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== Contributing to Twenty Twenty-Five ===
2+
3+
= Minifying CSS =
4+
5+
Twenty Twenty-Five has a single stylesheet `style.css` which is enqueued in addition to the global styles coming from core. On a normal production site, when `SCRIPT_DEBUG` is disabled, then the minified version `style.min.css` will be enqueued instead. If you make a change to `style.css`, you'll need to re-minify the `style.min.css` using the built-in npm build tool. As always, it is preferable to use the Site Editor to supply Additional CSS instead of directly editing the theme stylesheet.
6+
7+
Installation instructions
8+
9+
1. Using a command line interface, go to the “twentytwentyfive” directory `cd /my-computer/local-wordpress-install/src/wp-content/themes/twentytwentyfive`.
10+
11+
2. Type `npm install` into the command line, and press the [return] key, to install all Node.js dependencies.
12+
13+
3. The dependencies may take a few minutes to download but once it completes, you’re done.
14+
15+
Usage instructions
16+
17+
1. After making a change to the `style.css` file, run `npm run build` from within the theme directory to regenerate `style.min.css` with your new changes.
18+
19+
2. You can also “watch” the theme directory for CSS changes and re-minify the CSS anytime a change occurs by running: `npm run watch`.

src/wp-content/themes/twentytwentyfive/functions.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,22 @@ function twentytwentyfive_editor_style() {
3939
endif;
4040
add_action( 'after_setup_theme', 'twentytwentyfive_editor_style' );
4141

42-
// Enqueues style.css on the front.
42+
// Enqueues the theme stylesheet on the front.
4343
if ( ! 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
4848
*
4949
* @return void
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' )
5760
);

0 commit comments

Comments
 (0)