Skip to content

PostCSS Plugin

PostCSS plugin pre UnoCSS. Podporuje direktívy @apply, @screen a theme().

Zdrojový kód

WARNING

Tento balík je momentálne v experimentálnom stave. Nedrží sa semver a môže zaviesť zmeny v patch verziách.

Inštalácia

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;

Použitie

@unocss

@unocss at-rule je placeholder. Bude nahradený vygenerovaným CSS.

Môžete tiež vstreknúť každú vrstvu samostatne:

css
@unocss preflights;
@unocss default;

/*
  Fallback vrstva. Vždy sa odporúča zahrnúť.
  Iba nepoužité vrstvy budú sem vstreknuté.
*/
@unocss;

Ak chcete zahrnúť všetky vrstvy bez ohľadu na to, či boli predtým zahrnuté alebo nie, môžete použiť @unocss all. Toto je užitočné, ak chcete zahrnúť vygenerované CSS do viacerých súborov.

css
@unocss all;

@apply

css
.custom-div {
  @apply text-center my-0 font-medium;
}

Bude transformované na:

css
.custom-div {
  margin-top: 0rem;
  margin-bottom: 0rem;
  text-align: center;
  font-weight: 500;
}

@screen

Direktíva @screen vám umožňuje vytvárať media queries, ktoré odkazujú na vaše breakpointy podľa názvu, ktoré pochádzajú z theme.breakpoints.

css
.grid {
  @apply grid grid-cols-2;
}
@screen xs {
  .grid {
    @apply grid-cols-1;
  }
}
@screen sm {
  .grid {
    @apply grid-cols-3;
  }
}
/* ... */

Bude transformované na:

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));
  }
}
/* ... */

Podpora variantov breakpointov

@screen tiež podporuje varianty lt, at

@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;
  }
}
/* ... */

Bude transformované na:

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;
  }
}
/* ... */

Bude transformované na:

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()

Použite funkciu theme() na prístup k hodnotám konfigurácie témy pomocou notácie s bodkami.

css
.btn-blue {
  background-color: theme('colors.blue.500');
}

Bude skompilované na:

css
.btn-blue {
  background-color: #3b82f6;
}

Released under the MIT License.