PostCSS Plugin
UnoCSS용 PostCSS 플러그인. @apply
, @screen
및 theme()
지시문을 지원합니다.
WARNING
이 패키지는 현재 실험적 상태입니다. semver를 따르지 않으며 패치 버전에서 breaking changes를 도입할 수 있습니다.
설치
bash
pnpm add -D unocss @unocss/postcss
bash
yarn add -D unocss @unocss/postcss
bash
npm install -D unocss @unocss/postcss
bash
bun add -D unocss @unocss/postcss
ts
import UnoCSS from '@unocss/postcss'
export default {
plugins: [
UnoCSS(),
],
}
ts
import { defineConfig, presetWind3 } from 'unocss'
export default defineConfig({
content: {
filesystem: [
'**/*.{html,js,ts,jsx,tsx,vue,svelte,astro}',
],
},
presets: [
presetWind3(),
],
})
css
@unocss;
사용법
@unocss
@unocss
at-rule은 플레이스홀더입니다. 생성된 CSS로 대체됩니다.
각 레이어를 개별적으로 주입할 수도 있습니다:
css
@unocss preflights;
@unocss default;
/*
폴백 레이어. 항상 포함하는 것이 권장됩니다.
사용되지 않은 레이어만 여기에 주입됩니다.
*/
@unocss;
이전에 포함되었는지 여부에 관계없이 모든 레이어를 포함하려면 @unocss all
을 사용할 수 있습니다. 여러 파일에 생성된 CSS를 포함하려는 경우에 유용합니다.
css
@unocss all;
@apply
css
.custom-div {
@apply text-center my-0 font-medium;
}
다음으로 변환됩니다:
css
.custom-div {
margin-top: 0rem;
margin-bottom: 0rem;
text-align: center;
font-weight: 500;
}
@screen
@screen
지시문을 사용하면 theme.breakpoints
에서 나오는 이름으로 브레이크포인트를 참조하는 미디어 쿼리를 만들 수 있습니다.
css
.grid {
@apply grid grid-cols-2;
}
@screen xs {
.grid {
@apply grid-cols-1;
}
}
@screen sm {
.grid {
@apply grid-cols-3;
}
}
/* ... */
다음으로 변환됩니다:
css
.grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 320px) {
.grid {
grid-template-columns: repeat(1, minmax(0, 1fr));
}
}
@media (min-width: 640px) {
.grid {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
}
/* ... */
브레이크포인트 Variant 지원
@screen
은 lt
、at
variant도 지원합니다
@screen lt
css
.grid {
@apply grid grid-cols-2;
}
@screen lt-xs {
.grid {
@apply grid-cols-1;
}
}
@screen lt-sm {
.grid {
@apply grid-cols-3;
}
}
/* ... */
다음으로 변환됩니다:
css
.grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (max-width: 319.9px) {
.grid {
grid-template-columns: repeat(1, minmax(0, 1fr));
}
}
@media (max-width: 639.9px) {
.grid {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
}
/* ... */
@screen at
css
.grid {
@apply grid grid-cols-2;
}
@screen at-xs {
.grid {
@apply grid-cols-1;
}
}
@screen at-xl {
.grid {
@apply grid-cols-3;
}
}
@screen at-xxl {
.grid {
@apply grid-cols-4;
}
}
/* ... */
다음으로 변환됩니다:
css
.grid {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (min-width: 320px) and (max-width: 639.9px) {
.grid {
grid-template-columns: repeat(1, minmax(0, 1fr));
}
}
@media (min-width: 1280px) and (max-width: 1535.9px) {
.grid {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
}
@media (min-width: 1536px) {
.grid {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
}
/* ... */
theme()
theme()
함수를 사용하여 점 표기법으로 테마 설정 값에 접근하세요.
css
.btn-blue {
background-color: theme('colors.blue.500');
}
다음으로 컴파일됩니다:
css
.btn-blue {
background-color: #3b82f6;
}