Repository navigation
Twenty Twenty-One: Serve minified stylesheets - #16416
HrithikDalal wants to merge 1 commit into
Conversation
Load minified copies of the main, RTL, print and dark mode stylesheets unless `SCRIPT_DEBUG` is enabled, as Twenty Twenty-Two and Twenty Twenty-Five already do. The minified files are built by the `cssmin:themes` Grunt task for core builds, and by the theme's own `npm run build` for the theme ZIP. They are not committed. The RTL stylesheet uses the `suffix` data so that `style-rtl.min.css` is loaded. See #64109.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the stylesheet minification and build-packaging changes.
No open issues 🎉
1 file not reviewed
src/wp-content/themes/twentytwentyone/package-lock.json: Generated file
What changed in this PR
Updates Twenty Twenty-One to serve minified frontend stylesheets unless SCRIPT_DEBUG is enabled, aligning it with newer bundled themes.
Changes:
- Adds minified stylesheet loading, including RTL, print, and dark-mode variants.
- Generates all five minified files through core builds and theme ZIP packaging.
- Excludes generated files from Git and Stylelint, and documents the build process.
| File | Description |
|---|---|
src/wp-content/themes/twentytwentyone/style.css.map |
Updates mappings for the added header comment. |
src/wp-content/themes/twentytwentyone/style.css |
Documents debug-only loading and rebuilding. |
src/wp-content/themes/twentytwentyone/style-rtl.css |
Adds the same documentation to RTL CSS. |
src/wp-content/themes/twentytwentyone/package.json |
Adds cssnano and five minification scripts. |
src/wp-content/themes/twentytwentyone/package-lock.json |
Locks minification dependencies and related updates. |
src/wp-content/themes/twentytwentyone/functions.php |
Selects minified main and print styles, with RTL suffix handling. |
src/wp-content/themes/twentytwentyone/classes/class-twenty-twenty-one-dark-mode.php |
Selects minified dark-mode styles for both directions. |
src/wp-content/themes/twentytwentyone/assets/sass/01-settings/file-header.scss |
Adds build guidance to the source header. |
src/wp-content/themes/twentytwentyone/.stylelintignore |
Excludes minified CSS from linting. |
Gruntfile.js |
Includes five stylesheets in core minification. |
.gitignore |
Ignores generated minified theme stylesheets. |
.github/workflows/test-and-zip-default-themes.yml |
Builds theme assets before ZIP packaging. |
Review effort: Balanced
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Twenty Twenty-One now loads minified stylesheets unless
SCRIPT_DEBUGis enabled, the same way Twenty Twenty-Two and Twenty Twenty-Five do (#63012). This picks up #10860 and addresses the review feedback left there:style,style-rtl,print,style-dark-modeandstyle-dark-mode-rtl.suffixdata, so right-to-left sites loadstyle-rtl.min.css..gitignore, built by thecssmin:themesGrunt task for core builds, and by the theme'snpm run buildfor the theme ZIP (added to the minification steps intest-and-zip-default-themes.yml).get_template_directory_uri().style.cssgets the same "only served whenSCRIPT_DEBUGis enabled" note as Twenty Twenty-Five, with the wording suggested on Minify stylesheets for twentytwentyone theme. #10860.*.min.cssis added to.stylelintignore, sobuild:stylelintdoesn't rewrite the minified files on the next build. The theme'spostcss.config.js(postcss-css-variableswithpreserve: false) is not applied to the minified files, becausepostcss-cliskips the config file when--useis passed.Adding
cssnanoupdates a few existing packages in the lockfile within their current ranges.npm run buildstill reproduces the committed CSS exactly.The other classic themes will follow in a separate PR, which then unblocks #58519.
Testing
npm run build:dev(ornpx grunt cssmin:themes --dev) and check that the five.min.cssfiles are created intwentytwentyone/andtwentytwentyone/assets/css/, and thatgit statusdoesn't list them.SCRIPT_DEBUGset tofalse, view a post.style.min.css,print.min.cssandstyle-dark-mode.min.cssload.style-rtl.min.cssandstyle-dark-mode-rtl.min.cssload.SCRIPT_DEBUGset totrue, the unminified files load as before.src/wp-content/themes/twentytwentyone, runnpm ci && npm run buildtwice. The minified files are created andgit diffstays empty.I compared computed styles for every element on a single post with
SCRIPT_DEBUGon and off, and they were identical.Trac ticket: https://core.trac.wordpress.org/ticket/64109
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Co-authoring the change. Reviewed and tested by me.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.