unocss: `transformerVariantGroup` not working with `postcss` for `next.js` 13 (app directory)
UnoCSS version
latest
Describe the bug
Hi, sorry if this is marked somewhere, as I tried my best to search through but seems no one has raised this. Seems adding transformers into uno.config.ts has no effect when using postcss plugin? How do I make it support transformerVariantGroup?
Otherwise things like after:(xxx1 xxx2) won’t work and it will be a nightmare to write after:xxx1 after:xxx2
Reproduction
The same as in examples folder, I can’t get the codesandbox running up due to limit on their disk space
System Info
No response
Validations
- Read the Contributing Guidelines.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 7
- Comments: 23 (12 by maintainers)
I’ve had issues with this myself, but if you think about it, it’s unclear how
postcsscould really support transformers like this.In the JSX code, the class name applied to the element is something like
md:(bg-blue text-white). To the DOM, that’s just two class names:md:(bg-blueandtext-white). Uno has to be somewhere in the middle of the actual code transpilation process here, rewriting that tomd:bg-blueandmd:text-whitebefore handing the source to NextJS.With a transformer like attributify, I assume you can do everything in CSS by selecting on the attributes like
[bg:"blue"], no source code transformation necessary since the source remains valid. That would explain it working in Next/PostCSS only. But the same isn’t really possible with variant groups, as the actual class names themselves aren’t valid and must be changed before execution.For my part, I have been trying to integrate my own library of UI components which uses UnoCSS into a Next app. The solution I ultimately ended up with was to process the output files of that library with Uno’s CLI to rewrite all variant-group class names in place before publishing (see here, it’s a step in my multi-step build process for the library).
I’m not sure what you’d do if you’re trying to use variant groups within the source of the Next app itself. You may want to just run the CLI in watch mode on your source files to have it automatically rewrite your class names as you go. Then you can at least benefit by authoring grouped rules, even if the code that results will ungroup them when you save.
To reduce complexity and increase consistency, I would probably avoid using variant group in a Next app entirely and accept the extra typing. Thankfully I use Vite for most things.
Maybe we can add another package that can be processed by parcel
Due to the lack of a minimal reproducible demo, I will temporarily close this issue. Please feel free to open it when a reproducible demo is provided.
Ah yeah… that’s a bit frustrating. Honestly the postcss support is already pretty good, since most of things are working out of the box after following the official next.js 13 example. I just want to know how transformers really working (or are they even supported) in postcss way🤣
Maybe all transformers is not work? In my test,
transformerCompileClassis not work too.