Skip to content

Integrazione Astro

L'integrazione UnoCSS per Astro: @unocss/astro. Controlla l'esempio.

Installazione

bash
pnpm add -D unocss
bash
yarn add -D unocss
bash
npm install -D unocss
bash
bun add -D unocss
ts
import { defineConfig } from 'astro/config'
import UnoCSS from 'unocss/astro'

export default defineConfig({
  integrations: [
    UnoCSS(),
  ],
})

Crea un file uno.config.ts:

ts
import { defineConfig } from 'unocss'

export default defineConfig({
  // ...opzioni UnoCSS
})

Reset Stile

Per impostazione predefinita, il reset di stile del browser non verrà iniettato. Per abilitarlo, installa il pacchetto @unocss/reset:

bash
pnpm add -D @unocss/reset
bash
yarn add -D @unocss/reset
bash
npm install -D @unocss/reset
bash
bun add -D @unocss/reset

E aggiorna il tuo astro.config.ts:

ts
import { defineConfig } from 'astro/config'
import UnoCSS from 'unocss/astro'

export default defineConfig({
  integrations: [
    UnoCSS({
      injectReset: true // o un percorso al file reset
    }),
  ],
})

Utilizzo senza preset

Questo plugin non viene fornito con preset predefiniti.

bash
pnpm add -D @unocss/astro
bash
yarn add -D @unocss/astro
bash
npm install -D @unocss/astro
bash
bun add -D @unocss/astro
ts
import UnoCSS from '@unocss/astro'

export default {
  integrations: [
    UnoCSS(),
  ],
}

Per maggiori dettagli, consulta il plugin Vite.

INFO

Se stai costruendo un meta framework su UnoCSS, vedi questo file per un esempio su come collegare i preset predefiniti.

Note

I componenti client:only devono essere posizionati nella cartella components o aggiunti alla configurazione content di UnoCSS per essere elaborati.

Released under the MIT License.