Skip to content

컴파일 클래스 변환기

클래스 그룹을 하나의 클래스로 컴파일합니다. Windi CSS의 컴파일 모드@UltraCakeBakery이슈 #948에서 영감을 받았습니다.

설치

bash
pnpm add -D @unocss/transformer-compile-class
bash
yarn add -D @unocss/transformer-compile-class
bash
npm install -D @unocss/transformer-compile-class
bash
bun add -D @unocss/transformer-compile-class
ts
import transformerCompileClass from '@unocss/transformer-compile-class'
import { defineConfig } from 'unocss'

export default defineConfig({
  // ...
  transformers: [
    transformerCompileClass(),
  ],
})

TIP

이 프리셋은 unocss 패키지에 포함되어 있으며, 다음과 같이 가져올 수도 있습니다:

ts
import { transformerCompileClass } from 'unocss'

사용법

클래스 문자열의 시작 부분에 :uno:를 추가하여 컴파일 대상으로 표시합니다.

예시:

html
<div class=":uno: text-center sm:text-left">
  <div class=":uno: text-sm font-bold hover:text-red" />
</div>

다음과 같이 컴파일됩니다:

html
<div class="uno-qlmcrp">
  <div class="uno-0qw2gr" />
</div>
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;
  }
}

옵션

옵션을 사용하여 컴파일 클래스의 트리거 문자열과 접두사를 구성할 수 있습니다. 자세한 내용은 타입을 참조하세요.

도구

ESLint

전체 프로젝트에서 클래스 컴파일 변환기를 강제하는 eslint 규칙이 있습니다: @unocss/enforce-class-compile

사용법:

json
{
  "plugins": ["@unocss"],
  "rules": {
    "@unocss/enforce-class-compile": "warn"
  }
}

라이선스

Released under the MIT License.