CLI Commands
Headwind provides a powerful command-line interface for building, watching, and analyzing your CSS.
Installation
Install Headwind globally or locally:
# Global (use anywhere)
bun add --global headwind
# Local (project-specific)
bun add --dev headwindCommands
build
Build CSS from your content files.
headwind build [options]Options:
--output <path>- Output CSS file path--minify- Minify CSS output--watch- Watch for file changes--content <pattern>- Content file pattern--config <path>- Path to config file--verbose- Show detailed output--no-preflight- Skip preflight CSS
Examples:
# Basic build
headwind build
# Build with custom output
headwind build --output ./dist/styles.css
# Build and minify
headwind build --minify
# Build with specific content
headwind build --content "./src/**/*.tsx"
# Build with custom config
headwind build --config ./custom.config.ts
# Build with verbose output
headwind build --verbose
# Build without preflight CSS
headwind build --no-preflightOutput:
🚀 Building CSS...
✅ Built 1243 classes in 8.45ms
📝 Output: ./dist/headwind.css
📦 File size: 24.35 KBwatch
Build and watch for changes (equivalent to build --watch).
headwind watch [options]Options:
--output <path>- Output CSS file path--minify- Minify CSS output--content <pattern>- Content file pattern--config <path>- Path to config file--verbose- Show detailed output
Examples:
# Basic watch mode
headwind watch
# Watch with custom output
headwind watch --output ./dist/styles.css
# Watch with minification
headwind watch --minify
# Watch with verbose output
headwind watch --verboseOutput:
🚀 Building CSS...
✅ Built 1243 classes in 8.45ms
📝 Output: ./dist/headwind.css
📦 File size: 24.35 KB
👀 Watching for changes...
👀 Watching: ./src, ./components
📝 src/App.tsx changed, rebuilding...
✅ Built 1245 classes in 7.23msinit
Create a headwind.config.ts configuration file.
headwind init [options]Options:
--force- Overwrite existing config file
Examples:
# Create config
headwind init
# Force overwrite
headwind init --forceOutput:
✅ Created headwind.config.ts
Next steps:
1. Update the content paths in headwind.config.ts
2. Run: headwind buildGenerated file:
import type { HeadwindOptions } from 'headwind'
const config = {
content: ['./src/**/*.{html,js,ts,jsx,tsx}'],
output: './dist/headwind.css',
minify: false,
watch: false,
} satisfies HeadwindOptions
export default configanalyze
Analyze utility class usage and show statistics.
headwind analyze [options]Options:
--config <path>- Path to config file--verbose- Show detailed output--json- Output as JSON--top <n>- Show top N most used classes (default: 10)
Examples:
# Basic analysis
headwind analyze
# Show top 20 utilities
headwind analyze --top 20
# JSON output
headwind analyze --json
# Detailed analysis
headwind analyze --verboseOutput:
🔍 Analyzing utility classes...
📊 Total classes: 1243
⏱️ Build time: 8.45ms
📦 Output size: 24.35 KB
🏷️ Utility groups (top 10):
flex 156 classes
text 142 classes
bg 98 classes
p 87 classes
m 76 classes
w 54 classes
h 43 classes
border 38 classes
rounded 32 classes
shadow 28 classesJSON output (--json):
{
"totalClasses": 1243,
"buildTime": 8.45,
"outputSize": 24932,
"utilityGroups": {
"flex": 156,
"text": 142,
"bg": 98
},
"topClasses": [
"flex",
"items-center",
"justify-between"
]
}clean
Remove the output CSS file.
headwind clean [options]Options:
--config <path>- Path to config file
Examples:
# Clean output
headwind clean
# Clean with custom config
headwind clean --config ./custom.config.tsOutput:
✅ Removed ./dist/headwind.csspreflight
Generate only the preflight (reset) CSS.
headwind preflight [options]Options:
--output <path>- Output CSS file path (default:./preflight.css)
Examples:
# Generate preflight CSS
headwind preflight
# Custom output path
headwind preflight --output ./reset.cssOutput:
✅ Generated preflight CSS
📝 Output: ./preflight.css
📦 File size: 3.21 KBversion
Show the Headwind version.
headwind version
# or
headwind --versionOutput:
1.0.0help
Show help information.
headwind --help
# or
headwind [command] --helpGlobal Options
These options work with all commands:
--config <path>- Path to custom config file--verbose- Show detailed output
Configuration Priority
CLI options override configuration file settings:
# Config file specifies: output: './dist/styles.css'
headwind build --output ./public/app.css
# Actual output: ./public/app.css (CLI option wins)Priority order (highest to lowest):
- CLI options
- Config file
- Default values
Using with Package Managers
Bun (recommended)
# Run locally installed
bunx headwind build
# Run scripts
bun run buildnpm
# Run locally installed
npx headwind build
# Run scripts
npm run buildpnpm
# Run locally installed
pnpm dlx headwind build
# Run scripts
pnpm buildYarn
# Run locally installed
yarn headwind build
# Run scripts
yarn buildnpm Scripts
Add Headwind commands to your package.json:
{
"scripts": {
"dev": "headwind watch & vite dev",
"build": "headwind build --minify && vite build",
"css:build": "headwind build",
"css:watch": "headwind watch",
"css:analyze": "headwind analyze --verbose",
"css:clean": "headwind clean"
}
}Continuous Integration
GitHub Actions
# .github/workflows/ci.yml
name: CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v1
- name: Install dependencies
run: bun install
- name: Build CSS
run: bun run headwind build --minify
- name: Run tests
run: bun testGitLab CI
# .gitlab-ci.yml
build:
image: oven/bun:latest
script:
- bun install
- bun run headwind build --minify
artifacts:
paths:
- dist/headwind.cssVercel
{
"buildCommand": "headwind build --minify && next build",
"outputDirectory": ".next"
}Netlify
[build]
command = "headwind build --minify && npm run build"
publish = "dist"Advanced Usage
Custom Configuration Files
Specify different configs for different environments:
# Development
headwind build --config ./headwind.dev.config.ts
# Production
headwind build --config ./headwind.prod.config.ts --minify
# Testing
headwind build --config ./headwind.test.config.tsProgrammatic Usage
While the CLI is convenient, you can also use Headwind programmatically:
import { build, buildAndWrite } from 'headwind'
// Build only (get result)
const result = await build({
content: ['./src/**/*.tsx'],
output: './dist/headwind.css',
minify: true,
})
console.log(`Built ${result.classes.size} classes in ${result.duration}ms`)
// Build and write to file
await buildAndWrite({
content: ['./src/**/*.tsx'],
output: './dist/headwind.css',
minify: true,
})Combine Multiple Commands
# Clean, build, and analyze
headwind clean && headwind build --minify && headwind analyze
# Watch in one terminal, dev server in another
headwind watch &
npm run devEnvironment Variables
Use environment variables for dynamic configuration:
# Set environment
export NODE_ENV=production
# Build with env-specific config
headwind build --minify// headwind.config.ts
const isProd = process.env.NODE_ENV === 'production'
const config = {
output: isProd ? './dist/headwind.min.css' : './dist/headwind.css',
minify: isProd,
}Troubleshooting
Command Not Found
Problem: command not found: headwind
Solutions:
Install globally:
bashbun add --global headwindOr use with package runner:
bashbunx headwind build # or npx headwind buildOr use npm scripts:
json{ "scripts": { "build": "headwind build" } }
Permission Denied
Problem: Permission errors when writing files
Solutions:
Check output directory permissions:
bashls -la ./distCreate directory if it doesn't exist:
bashmkdir -p ./distFix permissions:
bashchmod -R u+w ./dist
Config Not Loading
Problem: Custom config not being used
Solutions:
Verify config path:
bashheadwind build --config ./headwind.config.ts --verboseCheck config file syntax:
typescript// Must have default export export default configEnsure TypeScript is installed:
bashbun add --dev typescript
Build Failures
Problem: Build fails with errors
Solutions:
Run with verbose output:
bashheadwind build --verboseCheck content patterns:
bash# Test if files exist ls -la ./src/**/*.tsxValidate config:
typescript// Use type checking import type { HeadwindOptions } from 'headwind' const config = { content: ['./src/**/*.tsx'], output: './dist/headwind.css', } satisfies HeadwindOptions // Type error will show if invalid
Performance Tips
Use specific content patterns:
bash# ❌ Slow headwind build --content "./**/*.tsx" # ✅ Fast headwind build --content "./src/**/*.tsx"Exclude unnecessary files:
typescriptcontent: [ './src/**/*.tsx', '!./src/**/*.test.tsx', // Exclude tests ]Use watch mode in development:
bash# Faster than rebuilding manually headwind watchEnable minify only in production:
bash# Development (fast) headwind build # Production (optimized) headwind build --minify
Related
- Configuration - Configuration options
- Watch Mode - Automatic rebuilding
- Programmatic API - Use Headwind in code