asset_shrink 0.1.0
asset_shrink: ^0.1.0 copied to clipboard
A zero-history, quality-gated Flutter and Dart dev-time asset compressor (PNG/JPEG) with native CLI and pure-Dart fallback.
example/example.md
asset_shrink Example #
This document demonstrates how to configure and use asset_shrink in your Flutter or Dart project.
1. Installation #
Add asset_shrink to your pubspec.yaml under dev_dependencies:
dev_dependencies:
asset_shrink: ^0.1.0
2. Configuration (Optional) #
Configure compression settings in your pubspec.yaml:
asset_shrink:
assets_dir: assets
png_quality: "90-100"
jpg_quality: 90
exclude:
- "assets/do_not_touch/**"
- "assets/icons/no_shrink.png"
3. Usage #
Run the tool from your project root:
# Compress all assets in the configured assets directory
dart run asset_shrink
# Preview changes without modifying files
dart run asset_shrink --dry-run
# Compress a custom directory with specific quality settings
dart run asset_shrink custom/assets --quality 80-95 --jpg-quality 85 --verbose
4. Programmatic Usage in Dart #
import 'dart:io';
import 'package:asset_shrink/asset_shrink.dart';
void main() async {
final config = await Config.loadFromPubspec(File('pubspec.yaml'));
final runner = CliRunner(
config: config,
targetDir: 'assets',
dryRun: false,
);
final report = await runner.run();
print('Saved ${formatBytes(report.totalBytesSaved)} across ${report.compressedCount} files!');
}