Plugin PostCSS
Plugin PostCSS para UnoCSS. Suporta diretivas @apply
, @screen
e theme()
.
WARNING
Este pacote está atualmente em estado experimental. Não segue semver e pode introduzir alterações significativas em versões de patch.
Instalar
pnpm add -D unocss @unocss/postcss
yarn add -D unocss @unocss/postcss
npm install -D unocss @unocss/postcss
bun add -D unocss @unocss/postcss
import UnoCSS from '@unocss/postcss'
export default {
plugins: [
UnoCSS(),
],
}
import { defineConfig, presetWind3 } from 'unocss'
export default defineConfig({
content: {
filesystem: [
'**/*.{html,js,ts,jsx,tsx,vue,svelte,astro}',
],
},
presets: [
presetWind3(),
],
})
@unocss;
Uso
@unocss
A regra at-rule @unocss
é um espaço reservado. Será substituída pelo CSS gerado.
Você também pode injetar cada camada individualmente:
@unocss preflights;
@unocss default;
/*
Camada de fallback. É sempre recomendado incluir.
Apenas camadas não utilizadas serão injetadas aqui.
*/
@unocss;
Se você quiser incluir todas as camadas, independentemente de já terem sido incluídas ou não, pode usar @unocss all
. Isso é útil se você quiser incluir CSS gerado em múltiplos arquivos.
@unocss all;
@apply
.custom-div {
@apply text-center my-0 font-medium;
}
Será transformado em:
.custom-div {
margin-top: 0rem;
margin-bottom: 0rem;
text-align: center;
font-weight: 500;
}
@screen
A diretiva @screen
permite criar consultas de mídia que fazem referência aos seus pontos de interrupção por nome, provenientes de theme.breakpoints
.
.grid {
@apply grid grid-cols-2;
}
@screen xs {
.grid {
@apply grid-cols-1;
}
}
@screen sm {
.grid {
@apply grid-cols-3;
}
}
/* ... */
Será transformado em:
.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));
}
}
/* ... */
Suporte a Variantes de Pontos de Interrupção
@screen
também suporta variantes lt
e at
@screen lt
.grid {
@apply grid grid-cols-2;
}
@screen lt-xs {
.grid {
@apply grid-cols-1;
}
}
@screen lt-sm {
.grid {
@apply grid-cols-3;
}
}
/* ... */
Será transformado em:
.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
.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;
}
}
/* ... */
Será transformado em:
.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()
Use a função theme()
para acessar os valores da sua configuração de tema usando notação de ponto.
.btn-blue {
background-color: theme('colors.blue.500');
}
Will be compiled to:
.btn-blue {
background-color: #3b82f6;
}