Astro Integration
การผสานรวม UnoCSS สำหรับ Astro: @unocss/astro ตรวจสอบ ตัวอย่าง
การติดตั้ง
bash
pnpm add -D unocssbash
yarn add -D unocssbash
npm install -D unocssbash
bun add -D unocssts
import { defineConfig } from 'astro/config'
import UnoCSS from 'unocss/astro'
export default defineConfig({
integrations: [
UnoCSS(),
],
})สร้างไฟล์ uno.config.ts:
ts
import { defineConfig } from 'unocss'
export default defineConfig({
// ...UnoCSS options
})Style Reset
โดยค่าเริ่มต้น browser style reset จะไม่ถูก inject เพื่อเปิดใช้งาน ให้ติดตั้งแพ็กเกจ @unocss/reset:
bash
pnpm add -D @unocss/resetbash
yarn add -D @unocss/resetbash
npm install -D @unocss/resetbash
bun add -D @unocss/resetและอัปเดต astro.config.ts ของคุณ:
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
}),
],
})การใช้งานโดยไม่มี presets
plugin นี้ไม่มาพร้อมกับ default presets ใดๆ
bash
pnpm add -D @unocss/astrobash
yarn add -D @unocss/astrobash
npm install -D @unocss/astrobash
bun add -D @unocss/astrots
import UnoCSS from '@unocss/astro'
export default {
integrations: [
UnoCSS(),
],
}สำหรับรายละเอียดเพิ่มเติม โปรดดูที่ Vite plugin
INFO
หากคุณกำลังสร้าง meta framework บน UnoCSS ดู ไฟล์นี้ สำหรับตัวอย่างวิธีการ bind default presets
หมายเหตุ
คอมโพเนนต์ client:only ต้องวางในโฟลเดอร์ components หรือเพิ่มใน content config ของ UnoCSS เพื่อให้ถูกประมวลผล