Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(core): allow postprocessors to append or remove rules#5010

Merged
zyyv merged 3 commits into
unocss:mainfrom
Menci:postprocess-append-or-remove
Dec 2, 2025
Merged

feat(core): allow postprocessors to append or remove rules#5010
zyyv merged 3 commits into
unocss:mainfrom
Menci:postprocess-append-or-remove

Conversation

@Menci

@Menci Menci commented Dec 2, 2025

Copy link
Copy Markdown
Contributor

Currently the postprocess hook only allow to modify the existing rule object, not append more rules or remove the existing rule. However, sometimes we need to transform a rule to multiple rules. For example, color fallback:

/* Before post-processing: an OKLCH color only */
.text-shadow-color-blue-300 { --un-text-shadow-color: oklch(0.8 0.11 256); }

/* After post-processing: add RGB fallback */
.text-shadow-color-blue-300 { --un-text-shadow-color: oklch(0.8 0.11 256); }
@supports not (color: oklch(0 0 0)) { .text-shadow-color-blue-300 { --un-text-shadow-color: #8ec1ff; } }

Since PostCSS doesn't work well with UnoCSS (--at-apply is handled AFTER PostCSS!), built-in post-process hook is important for such transformations.

This PR allows the config.postprocess hook functions to return:

  • false: to remove the rule
  • Other falsy values: to keep the rule object (maybe mutated by the function, the original behavior)
  • An object: to replace the rule with a new rule object
  • An array: to replace the rule with an array of rules

@Menci Menci requested review from antfu and zyyv as code owners December 2, 2025 14:50
@netlify

netlify Bot commented Dec 2, 2025

Copy link
Copy Markdown

Deploy Preview for unocss ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 3fbf044
🔍 Latest deploy log https://app.netlify.com/projects/unocss/deploys/692f1247c5b19a0008079181
😎 Deploy Preview https://deploy-preview-5010--unocss.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new

pkg-pr-new Bot commented Dec 2, 2025

Copy link
Copy Markdown

Open in StackBlitz

commit: 3fbf044

Comment thread packages-engine/core/test/postprocess.test.ts Outdated

@zyyv zyyv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zyyv zyyv enabled auto-merge December 2, 2025 16:24
@zyyv zyyv added this pull request to the merge queue Dec 2, 2025
Merged via the queue into unocss:main with commit 298de3e Dec 2, 2025
11 checks passed
This was referenced Dec 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants