Skip to content

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)

Default behavior

Without a config file, the optimizer scans these default paths:

  • 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

Create an asset_optimizer.yaml at the workspace root:

yaml
asset_optimizer:
  paths:
    - apps/template_app/assets
    - packages/app_asset/assets

  svg:
    enabled: true

  png:
    enabled: true

  jpeg:
    enabled: true

  ignore:
    - "**/test/fixtures/**"
    - "**/golden/**"
FieldDefaultDescription
pathsapps/*/assets, packages/*/assetsDirectories to scan for assets
svg.enabledtrueWhether to optimize SVG files
png.enabledtrueWhether to optimize PNG files
jpeg.enabledtrueWhether 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.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.

Built by Banua Coder