Toolkit Extensions
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) |
Prerequisites
Optimization is done by external tools, which must be on your PATH: svgo (npm install -g svgo), oxipng (brew install oxipng) and jpegoptim (brew install jpegoptim). The command checks for each enabled format's tool up front and refuses to run, printing install instructions, if one is missing.
Default behavior
Without a config file, the optimizer scans these default paths:
apps/*/assetsapps/*/*/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
The asset_optimizer brick writes a starter asset_optimizer.yaml at the workspace root. Edit it, or create it yourself:
asset_optimizer:
paths:
- apps/template_app/assets
- packages/app_asset/assets
svg:
enabled: true
png:
enabled: true
level: 4 # oxipng level 1-6
jpeg:
enabled: true
quality: 80 # 1-100
ignore:
- "**/test/fixtures/**"
- "**/golden/**"| Field | Default | Description |
|---|---|---|
paths | apps/*/assets, 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 |
png.level | 4 | oxipng optimization level (1-6) |
jpeg.enabled | true | Whether to optimize JPEG files |
jpeg.quality | 80 | jpegoptim maximum quality (1-100) |
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.