svgm-node
v0.3.8
Published
svgm SVG optimizer — Node.js native addon
Readme
33x faster than SVGO with better compression. Native Rust performance via napi-rs, no WASM overhead.
Install
# npm
npm install -g svgm-node
# yarn
yarn global add svgm-node
# pnpm
pnpm add -g svgm-node
# bun
bun add -g svgm-nodePrebuilt binaries are available for:
| Platform | Architecture | |:--|:--| | Linux | x64 (glibc), x64 (musl) | | macOS | x64, arm64 (Apple Silicon) | | Windows | x64 |
CLI
Installing the package also provides a svgm command:
svgm icon.svg # Optimize in place
svgm icon.svg -o icon.min.svg # Write to different file
svgm icon.svg --stdout # Print to stdout
svgm icon.svg --dry-run # Preview without writing
svgm icon.svg --preset safe # Safe preset (20 passes)
svgm icon.svg --precision 2 # Override numeric precision
svgm *.svg # Multiple filesWhen piped, output goes to stdout automatically.
For the full-featured CLI (recursive directory mode, config files, progress bars), install via Rust:
cargo install svgm
JavaScript API
const { optimize, version } = require('svgm-node');
const result = optimize('<svg xmlns="http://www.w3.org/2000/svg">...</svg>');
console.log(result.data); // optimized SVG string
console.log(result.iterations); // convergence count
console.log(version()); // e.g. "0.3.2"ESM
import { optimize, version } from 'svgm-node';With options
const result = optimize(svgString, {
preset: 'safe', // "safe" | "default"
precision: 2, // numeric precision (default: 3)
passes: {
removeDesc: true, // enable opt-in passes
mergePaths: false, // disable specific passes
},
});API
optimize(svg: string, options?: OptimizeOptions): OptimizeResult
Optimizes an SVG string. Throws on invalid SVG input.
version(): string
Returns the svgm version.
Types
interface OptimizeOptions {
preset?: string; // "safe" | "default"
precision?: number; // numeric precision (default: 3)
passes?: Record<string, boolean>; // per-pass enable/disable
}
interface OptimizeResult {
data: string; // optimized SVG
iterations: number; // convergence iterations
}Presets
- safe — removal and normalization only (20 passes)
- default — full optimization (34 passes)
Links
License
Dual-licensed under MIT and Apache 2.0.
