Skip to content

Conversation

@Menci
Copy link
Contributor

@Menci Menci commented Dec 2, 2025

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
Copy link

netlify bot commented Dec 2, 2025

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
Copy link

pkg-pr-new bot commented Dec 2, 2025

Open in StackBlitz

commit: 3fbf044

Copy link
Member

@zyyv zyyv left a comment

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