Compile group of classes into one class
npm install @unocss/transformer-compile-classCompile group of classes into one class. Inspired by WindiCSS's compilation mode and #948 by @UltraCakeBakery.
``bash`
npm i -D @unocss/transformer-compile-class
`ts
import transformerCompileClass from '@unocss/transformer-compile-class'
// uno.config.ts
import { defineConfig } from 'unocss'
export default defineConfig({
// ...
transformers: [
transformerCompileClass(),
],
})
`
At the begin of your class strings, add :uno: at the begin of the strings to mark them for compilation. For example:
`html`
Will be compiled to:
`html`
`css``
.uno-qlmcrp {
text-align: center;
}
.uno-0qw2gr {
font-size: 0.875rem;
line-height: 1.25rem;
font-weight: 700;
}
.uno-0qw2gr:hover {
--un-text-opacity: 1;
color: rgb(248 113 113 / var(--un-text-opacity));
}
@media (min-width: 640px) {
.uno-qlmcrp {
text-align: left;
}
}
You can config the trigger string and prefix for compile class with the options. Refers to the types for details.
MIT License © 2021-PRESENT Anthony Fu