Skip to content

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 ​

bash
# 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.yaml

Flags ​

FlagAbbrDescription
--dry-run-dPreview changes without modifying files
--config-cPath 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/*/assets
  • apps/*/*/assets
  • packages/*/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:

yaml
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/**"
FieldDefaultDescription
pathsapps/*/assets, apps/*/*/assets, packages/*/assetsDirectories to scan for assets
svg.enabledtrueWhether to optimize SVG files
png.enabledtrueWhether to optimize PNG files
png.level4oxipng optimization level (1-6)
jpeg.enabledtrueWhether to optimize JPEG files
jpeg.quality80jpegoptim 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.2MB

CI integration ​

yaml
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 change

When 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.