Skip to content

CLI

Command line interface สำหรับ UnoCSS: @unocss/cli

  • 🍱 เหมาะสำหรับ backends แบบดั้งเดิมเช่น Laravel หรือ Kirby
  • 👀 รวม Watch mode
  • 🔌 รองรับ custom configurations ผ่าน uno.config.ts

การติดตั้ง

แพ็กเกจนี้มาพร้อมกับแพ็กเกจ unocss:

bash
pnpm add -D unocss
bash
yarn add -D unocss
bash
npm install -D unocss
bash
bun add -D unocss

คุณยังสามารถติดตั้ง standalone package:

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

INFO

หากคุณไม่พบ binary (เช่น กับ pnpm และมีเฉพาะ unocss ติดตั้ง) คุณจะต้องติดตั้ง standalone package @unocss/cli โดยเฉพาะ

การใช้งาน

คุณสามารถส่ง multiple glob patterns ไปยัง @unocss/cli:

bash
unocss "site/snippets/**/*.php" "site/templates/**/*.php"

ตัวอย่าง package configuration:

INFO

ตรวจสอบให้แน่ใจว่าได้เพิ่ม escaped quotes ใน npm script glob patterns ของคุณ

json
{
  "scripts": {
    "dev": "unocss \"site/{snippets,templates}/**/*.php\" --watch",
    "build": "unocss \"site/{snippets,templates}/**/*.php\""
  },
  "devDependencies": {
    "@unocss/cli": "latest"
  }
}

Development

เพิ่ม flag --watch (หรือ -w) เพื่อเปิดใช้งานการเฝ้าดูการเปลี่ยนแปลงไฟล์:

bash
unocss "site/{snippets,templates}/**/*.php" --watch

Production

bash
unocss "site/{snippets,templates}/**/*.php"

ไฟล์ uno.css สุดท้ายจะถูกสร้างไปยังไดเรกทอรีปัจจุบันโดยค่าเริ่มต้น

Built-in features

Configurations

สร้างไฟล์ configuration uno.config.js หรือ uno.config.ts ที่ root-level ของโปรเจคของคุณเพื่อปรับแต่ง UnoCSS

ts
import { defineConfig } from 'unocss'

export default defineConfig({
  cli: {
    entry: {}, // CliEntryItem | CliEntryItem[]
  },
  // ...
})

interface CliEntryItem {
  /**
   * Glob patterns to match files
   */
  patterns: string[]
  /**
   * The output filename for the generated UnoCSS file
   */
  outFile: string
}

สำหรับรายการตัวเลือก ไปที่เอกสาร UnoCSS configurations

Options

Options
-v, --versionแสดงเวอร์ชันปัจจุบันของ UnoCSS
-c, --config-file <file>Config file
-o, --out-file <file>ชื่อไฟล์ output สำหรับไฟล์ UnoCSS ที่สร้างขึ้น ค่าเริ่มต้นคือ uno.css ในไดเรกทอรีทำงานปัจจุบัน
--stdoutเขียนไฟล์ UnoCSS ที่สร้างขึ้นไปยัง STDOUT จะทำให้ --watch และ --out-file ถูกละเลย
-w, --watchระบุว่าไฟล์ที่พบโดย glob pattern ควรถูกเฝ้าดู
--preflightsเปิดใช้งาน preflight styles
--write-transformedอัปเดตไฟล์ต้นฉบับด้วย transformed utilities
-m, --minifyMinify generated CSS
-h, --helpแสดง CLI options ที่มี

Released under the MIT License.