Asset Optimizer Pro
The assets command optimizes image assets (SVG, PNG, JPEG) across the workspace to reduce app bundle size. It scans configured paths, applies format-specific optimization, and reports total savings.
Usage
# Optimize all assets with default settings
dart run monorepo_toolkit assets optimize
# Preview what would be optimized without writing
dart run monorepo_toolkit assets optimize --dry-run
# Use a custom config file
dart run monorepo_toolkit assets optimize --config custom_optimizer.yamlFlags
| Flag | Abbr | Description |
|---|---|---|
--dry-run | -d | Preview changes without modifying files |
--config | -c | Path to a YAML config file (relative to workspace root) |
Default behavior
Without a config file, the optimizer scans these default paths:
apps/*/assetspackages/*/assets
It processes SVG, PNG, and JPEG files by default. The following patterns are automatically ignored:
**/.dart_tool/****/build/****/.git/****/*.9.png(nine-patch images)
Configuration
Create an asset_optimizer.yaml at the workspace root:
asset_optimizer:
paths:
- apps/template_app/assets
- packages/app_asset/assets
svg:
enabled: true
png:
enabled: true
jpeg:
enabled: true
ignore:
- "**/test/fixtures/**"
- "**/golden/**"| Field | Default | Description |
|---|---|---|
paths | apps/*/assets, packages/*/assets | Directories to scan for assets |
svg.enabled | true | Whether to optimize SVG files |
png.enabled | true | Whether to optimize PNG files |
jpeg.enabled | true | Whether to optimize JPEG files |
ignore | [] | Additional glob patterns to skip (merged with defaults) |
Output
After optimization, the command prints a summary:
Found 24 asset file(s)
Summary:
Files processed: 24
Total savings: 1.2MBCI integration
steps:
- name: Optimize assets
run: dart run monorepo_toolkit assets optimize
- name: Check for unoptimized assets
run: |
dart run monorepo_toolkit assets optimize --dry-run
# Fail if any files would changeWhen to use this
Run the optimizer after adding or updating image assets. Integrate it into CI to catch unoptimized images before they reach production builds. This is especially valuable for apps with many icons and illustrations, where unoptimized SVGs and PNGs can add significant size to the app bundle.