This directory contains the build scripts for the asset pipeline that optimizes CSS, images, and other static assets for production.
The asset pipeline provides:
- CSS Processing - Minification, autoprefixing, and optimization
- Image Optimization - Multi-format responsive images with AVIF, WebP, and JPEG
- Asset Fingerprinting - Cache-busting hashes for CSS files
Processes CSS files using PostCSS with autoprefixer and cssnano.
Development Mode:
- Copies CSS files as-is for easier debugging
- Maintains readable formatting
Production Mode:
- Minifies CSS with cssnano
- Adds vendor prefixes with autoprefixer
- Reduces file size by ~24% (14KB → 11KB)
Usage:
# Runs automatically during Eleventy build
ELEVENTY_ENV=production npx @11ty/eleventyGenerates cache-busting versions of CSS files with MD5 hashes.
Features:
- Creates hashed copies of CSS files (e.g.,
tufte.css→tufte.1a669404.css) - Keeps original filenames for compatibility
- Generates
asset-manifest.jsonfor mapping
Output:
{
"tufte.css": "tufte.1a669404.css"
}Usage:
# Runs automatically after production builds
ELEVENTY_ENV=production npx @11ty/eleventy- Before: 832 lines, ~14KB unminified
- After: 1 line, ~11KB minified
- Savings: ~24% reduction in file size
- Formats: AVIF (best compression) → WebP (good compression) → JPEG (fallback)
- Quality Settings:
- AVIF: 80% quality, effort 4
- WebP: 85% quality
- JPEG: 85% quality, progressive
- Responsive Widths: 400px, 800px, 1280px, original
1. eleventy.before event
└── process-css.js runs
└── CSS files are processed/copied to _site/css/
2. Eleventy builds site
└── HTML, Markdown, templates processed
└── Images processed with eleventy-img
└── Static files copied
3. Production only: HTML minification
└── html-minifier-terser transform runs
4. eleventy.after event (production only)
└── fingerprint-assets.js runs
└── Creates hashed CSS files
└── Generates asset-manifest.json
PostCSS configuration is embedded directly in the build script:
// Process with PostCSS
const result = await postcss([autoprefixer, cssnano({ preset: "default" })]).process(css, {
from: inputPath,
to: outputPath,
});- Registers
eleventy.beforehook for CSS processing - Registers
eleventy.afterhook for fingerprinting - Configures eleventy-img with AVIF/WebP/JPEG formats
| Feature | Development | Production |
|---|---|---|
| CSS Minification | ✗ | ✓ |
| CSS Autoprefixing | ✗ | ✓ |
| HTML Minification | ✗ | ✓ |
| Asset Fingerprinting | ✗ | ✓ |
| Image Optimization | ✓ | ✓ |
The asset pipeline is designed for incremental builds:
- CSS Processing: Only processes changed CSS files
- Image Processing: eleventy-img caches processed images
- Fast Rebuilds: Development mode skips minification for speed
- Add CSS file to
src/css/ - File will be automatically processed during build
- Reference in templates with
/css/filename.css
- Add image to
src/media/or post directory - Use the
{% image %}shortcode in templates:{% image "path/to/image.jpg", "Alt text", "optional-class" %} - Images will be automatically optimized and made responsive
- Ensure
ELEVENTY_ENV=productionis set - Check console for PostCSS errors
- Verify production build is running
- Check
_site/css/asset-manifest.jsonexists
- Use development mode for local work
- Production builds are slower due to minification
- Image processing is cached between builds
Potential improvements:
- JavaScript bundling and minification (when needed)
- Brotli/gzip pre-compression
- Service worker for offline support
- Critical CSS inlining
- PurgeCSS for unused CSS removal