Skip to content

Tích hợp Astro

Tích hợp UnoCSS cho Astro: @unocss/astro. Xem ví dụ.

Cài đặt

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(),
  ],
})

Tạo tệp uno.config.ts:

ts
import { defineConfig } from 'unocss'

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

Đặt lại kiểu (Style Reset)

Theo mặc định, đặt lại kiểu trình duyệt sẽ không được chèn vào. Để bật nó, hãy cài đặt gói @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

Và cập nhật astro.config.ts của bạn:

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

export default defineConfig({
  integrations: [
    UnoCSS({
      injectReset: true // or a path to the reset file
    }),
  ],
})

Sử dụng không cần preset

Plugin này không đi kèm bất kỳ preset mặc định nào.

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(),
  ],
}

Để biết thêm chi tiết, vui lòng tham khảo Vite plugin.

INFO

Nếu bạn đang xây dựng một meta framework trên UnoCSS, xem tệp này để biết ví dụ về cách liên kết các preset mặc định.

Lưu ý

Các thành phần client:only phải được đặt trong thư mục components hoặc được thêm vào cấu hình content của UnoCSS để được xử lý.

Released under the MIT License.