Size Guard Pro
The size-guard command scans the workspace for files that exceed a configurable size threshold. This prevents accidentally committing large binary assets (images, fonts, videos) that bloat the repository.
Usage
# Check with default 500KB threshold
dart run monorepo_toolkit size-guard check
# Custom threshold
dart run monorepo_toolkit size-guard check --threshold 1MB
# Show detailed scan statistics
dart run monorepo_toolkit size-guard check --stats
# Add extra file extensions to scan
dart run monorepo_toolkit size-guard check -e psd -e ai
# Ignore specific paths
dart run monorepo_toolkit size-guard check -i "assets/legacy"Flags
| Flag | Abbr | Default | Description |
|---|---|---|---|
--threshold | -t | 500KB | Size threshold (e.g., 500KB, 1MB, 2GB) |
--extension | -e | see below | Additional file extensions to check |
--ignore | -i | see below | Additional paths to ignore |
--config | -c | size_guard.yaml | Path to YAML config file |
--stats | -s | false | Show detailed statistics (total files scanned, total bytes) |
The command exits with code 1 if any files exceed the threshold, making it suitable for CI gate checks.
Default extensions
The following extensions are scanned by default: png, jpg, jpeg, gif, webp, bmp, ico, svg, ttf, otf, woff, woff2, mp3, mp4, wav, avi, mov, webm, pdf, zip, tar, gz, rar, json, db, sqlite.
Default ignore paths
These directories are skipped: .git, .dart_tool, .idea, .vscode, build, node_modules, .fvm, .pub-cache, .gradle, ios/Pods, android/.gradle, coverage.
Configuration
Create a size_guard.yaml at the workspace root:
size_guard:
threshold: "1MB"
extensions:
- png
- jpg
- svg
- ttf
- mp4
ignore_paths:
- .git
- build
- node_modules
ignore_patterns:
- "**/test/fixtures/**"
- "**/golden/**"Command-line flags are merged with (not replacing) the config file values for extensions and ignore paths.
CI integration
steps:
- name: Check asset sizes
run: dart run monorepo_toolkit size-guard check --statsWhen to use this
Use size-guard in CI to prevent large assets from being committed. Common scenarios:
- A designer adds an unoptimized 5MB PNG to the assets folder
- A test fixture contains a large video file that should be in external storage
- Font files exceed expected sizes after a design system update