Skip to content

Commit 2389646

Browse files
committed
Bundled Themes: Add CSS minification support to Twenty Twenty
1 parent 0ad6fd2 commit 2389646

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

‎src/wp-content/themes/twentytwenty/functions.php‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,11 @@ function twentytwenty_register_block_patterns() {
194194
*/
195195
function twentytwenty_register_styles() {
196196

197-
$theme_version = wp_get_theme()->get( 'Version' );
197+
$theme_version = wp_get_theme()->get( 'Version' );
198+
$suffix = SCRIPT_DEBUG ? '' : '.min';
199+
$stylesheet_uri = SCRIPT_DEBUG ? get_stylesheet_uri() : str_replace( '.css', $suffix . '.css', get_stylesheet_uri() );
198200

199-
wp_enqueue_style( 'twentytwenty-style', get_stylesheet_uri(), array(), $theme_version );
201+
wp_enqueue_style( 'twentytwenty-style', $stylesheet_uri, array(), $theme_version );
200202
wp_style_add_data( 'twentytwenty-style', 'rtl', 'replace' );
201203

202204
// Enqueue the CSS file for the variable font, Inter.

‎src/wp-content/themes/twentytwenty/package-lock.json‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/wp-content/themes/twentytwenty/package.json‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "twentytwenty",
3-
"version": "3.0.0",
3+
"version": "3.0",
44
"description": "Default WP Theme",
55
"author": "The WordPress Contributors",
66
"license": "GPL-2.0-or-later",
@@ -26,6 +26,7 @@
2626
"@wordpress/scripts": "^30.27.0",
2727
"autoprefixer": "^10.4.22",
2828
"concurrently": "^9.2.1",
29+
"cssnano": "^7.1.2",
2930
"postcss": "^8.5.6",
3031
"postcss-cli": "^11.0.1",
3132
"rtlcss": "^4.3.0",
@@ -47,7 +48,7 @@
4748
"map": false
4849
},
4950
"scripts": {
50-
"build": "npm run build:vendor-prefixes && npm run build:rtl",
51+
"build": "npm run build:vendor-prefixes && npm run build:rtl && npm run build:minify",
5152
"build:rtl": "concurrently \"npm run build:rtl-style\" \"npm run build:rtl-esb\" \"npm run build:rtl-esc\"",
5253
"build:rtl-style": "rtlcss style.css style-rtl.css",
5354
"build:rtl-esb": "rtlcss assets/css/editor-style-block.css assets/css/editor-style-block-rtl.css",
@@ -56,6 +57,7 @@
5657
"build:vendor-prefixes-style": "postcss -r --no-map style.css assets/css/editor-style-block.css assets/css/editor-style-classic.css",
5758
"build:vendor-prefixes-esb": "postcss -r --no-map assets/css/editor-style-block.css ",
5859
"build:vendor-prefixes-esc": "postcss -r --no-map assets/css/editor-style-classic.css",
60+
"build:minify": "postcss style.css --use cssnano -o style.min.css --no-map",
5961
"lint:css": "wp-scripts lint-style 'style.css' 'assets/**/*.css'",
6062
"lint:js": "wp-scripts lint-js 'assets/**/*.js'",
6163
"lint:pkg-json": "wp-scripts lint-pkg-json"

‎src/wp-content/themes/twentytwenty/style.css‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ Use it to make something cool, have fun, and share what you've learned
2121
with others.
2222
*/
2323

24+
/*
25+
* IMPORTANT: This file is only served on the frontend when `SCRIPT_DEBUG` is enabled;
26+
* in most instances, the `style.min.css` file will be served. This theme uses SCSS for styles.
27+
* After making changes to SCSS files, run `npm run build` in the theme directory to compile
28+
* SCSS to CSS and regenerate the minified version.
29+
*/
30+
2431
/*--------------------------------------------------------------
2532
>>> TABLE OF CONTENTS:
2633
----------------------------------------------------------------

0 commit comments

Comments
 (0)