# svgpack
Fast SVG optimizer for build pipelines, implemented in Rust.
This repository contains the first working version of `svgpack` as a Rust workspace with:
- CLI command entrypoint
- Core optimization pipeline orchestration
- Basic parser helpers
- MVP optimizer passes
- Sprite generation (`symbol` format)
- React component code generation
- Duplicate detection
- Basic SVG analysis reporting
## Current status
Version target: `v0.1.0` (MVP foundation).
Implemented:
- `optimize` flow (single file or directory)
- `--in-place`, `--dry-run`, `--stats`, and `--format json`
- `sprite` subcommand
- `codegen` subcommand (`--framework react`)
- `dedup` subcommand
- `analyze` subcommand
## Workspace layout
```
svgpack/
├── Cargo.toml
├── crates/
│ ├── svgpack_cli/
│ ├── svgpack_core/
│ ├── svgpack_parser/
│ ├── svgpack_optimizer/
│ ├── svgpack_sprite/
│ ├── svgpack_codegen/
│ ├── svgpack_dedup/
│ ├── svgpack_analysis/
│ └── svgpack_config/
└── tests/
└── fixtures/
```
## Build
Requirements:
- Rust stable toolchain
- Cargo
Commands:
```bash
cargo fmt
cargo check
cargo test
```
## CLI usage
Run via cargo:
```bash
cargo run -p svgpack_cli -- <args>
```
Optimize:
```bash
cargo run -p svgpack_cli -- icons/ -o dist/icons/ --stats
```
Optimize in place:
```bash
cargo run -p svgpack_cli -- icons/ --in-place
```
Dry run:
```bash
cargo run -p svgpack_cli -- icons/ --dry-run --stats
```
JSON output:
```bash
cargo run -p svgpack_cli -- icons/ --format json
```
Sprite generation:
```bash
cargo run -p svgpack_cli -- sprite icons/ -o dist/sprite.svg
```
React codegen:
```bash
cargo run -p svgpack_cli -- codegen icons/ -o src/icons/ --framework react --index
```
Duplicate detection:
```bash
cargo run -p svgpack_cli -- dedup icons/
```
Analyze:
```bash
cargo run -p svgpack_cli -- analyze icons/
```
## Config
You can pass a JSON config with `--config`:
```bash
cargo run -p svgpack_cli -- --config svgpack.config.json icons/ -o dist/icons/
```
Supported now:
- `preset`
- `multipass`
- `max_passes`
- `passes` map (`enabled`, `precision`, `prefix`)
## Roadmap
- `v0.2`: stronger path/transforms optimization + better SVGO parity.
- `v0.3`: sprite improvements + React/Vue codegen hardening.
- `v0.4`: build-tool plugins (Vite/Rspack/Webpack) + watch mode.
- `v1.0`: stable API, regression corpus, performance benchmarks.
## Notes
- This is a first version focused on architecture and working command flow.
- Path-data optimization is still minimal and should be expanded in the next iteration.
- Visual regression tests and SVGO compatibility mapping are planned next.