Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Configure and use UnoCSS atomic CSS engine with presets like Wind (Tailwind-compatible), Icons, and Attributify.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/core-extracting.md
1---2name: unocss-extracting3description: How UnoCSS extracts utilities from source code4---56# Extracting78UnoCSS searches for utility usages in your codebase and generates CSS on-demand.910## Content Sources1112### Pipeline Extraction (Vite/Webpack)1314Most efficient - extracts from build tool pipeline.1516**Default file types:** `.jsx`, `.tsx`, `.vue`, `.md`, `.html`, `.svelte`, `.astro`, `.marko`1718**Not included by default:** `.js`, `.ts`1920```ts21export default defineConfig({22content: {23pipeline: {24include: [25/\.(vue|svelte|[jt]sx|mdx?|astro|html)($|\?)/,26'src/**/*.{js,ts}', // Add js/ts27],28},29},30})31```3233### Filesystem Extraction3435For files not in build pipeline:3637```ts38export default defineConfig({39content: {40filesystem: [41'src/**/*.php',42'public/*.html',43],44},45})46```4748### Inline Text Extraction4950```ts51export default defineConfig({52content: {53inline: [54'<div class="p-4 text-red">Some text</div>',55async () => (await fetch('https://example.com')).text(),56],57},58})59```6061## Magic Comments6263### @unocss-include6465Force scan a file:6667```ts68// @unocss-include69export const classes = {70active: 'bg-primary text-white',71}72```7374### @unocss-ignore7576Skip entire file:7778```ts79// @unocss-ignore80```8182### @unocss-skip-start / @unocss-skip-end8384Skip specific blocks:8586```html87<p class="text-green">Extracted</p>88<!-- @unocss-skip-start -->89<p class="text-red">NOT extracted</p>90<!-- @unocss-skip-end -->91```9293## Limitations9495UnoCSS works at **build time** - dynamic classes don't work:9697```html98<!-- Won't work! -->99<div class="p-${size}"></div>100```101102### Solutions103104**1. Safelist** - Pre-generate known values:105106```ts107safelist: ['p-1', 'p-2', 'p-3', 'p-4']108```109110**2. Static mapping** - List combinations statically:111112```ts113const colors = {114red: 'text-red border-red',115blue: 'text-blue border-blue',116}117```118119**3. Runtime** - Use `@unocss/runtime` for true runtime generation.120121## Custom Extractors122123```ts124extractors: [125{126name: 'my-extractor',127extract({ code }) {128return code.match(/class:[\w-]+/g) || []129},130},131]132```133134<!--135Source references:136- https://unocss.dev/guide/extracting137-->138