Skip to content

Conversation

@jsnajdr
Copy link
Member

@jsnajdr jsnajdr commented Jan 15, 2026

Improves how we deal with style imports that we inline into the transpiled JS code. Two improvements:

  • generate custom JS code for inserting the style element. It checks if the style element with the given data-wp-hash attribute already exists, and prevents inserting duplicate styles. That can reduce style duplication a lot when libraries like @wordpress/ui are bundled many times with various chunks (blocks, routes etc.)
  • minify the embedded code with cssnano. Makes the transpiled JS files smaller.

We're still using postcss here for both CSS modules and minification. In the near future I'd like to switch to lightningcss but they need to release a bugfixed version first.

How to test

look at built files for:

  • individual packages, like packages/ui/build-module/form/primitives/fieldset/legend.mjs
  • WP script, like build/scripts/components/index.js

and verify that they both contain the new CSS-inserting code with minified CSS literals.

@jsnajdr jsnajdr self-assigned this Jan 15, 2026
@jsnajdr jsnajdr added [Type] Build Tooling Issues or PRs related to build tooling [Package] wp-build /packages/wp-build labels Jan 15, 2026
@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jsnajdr <jsnajdr@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] wp-build /packages/wp-build [Type] Build Tooling Issues or PRs related to build tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants