A command-line tool for generating sprite sheets from SVG icons for use with MapLibre GL / Mapbox GL map styles.
- Converts SVG icons to sprite sheets (regular and retina/2x)
- Optimizes SVGs before processing
- Generates sprite metadata in MapLibre/Mapbox GL format
- Supports custom input/output directories
- Configurable sprite sheet prefix
# Clone the repository
git clone [repository-url]
cd maplibre-sprite-generator
# Install dependencies
yarn installBasic usage:
yarn start --input=./icons --output=./sprites--input, -i: Input directory containing SVG icons (default:./icons)--output, -o: Output directory for sprite sheets and metadata (default:./sprites)--optimize, -z: Enable/disable SVG optimization (default:true)--prefix, -p: Prefix for sprite filenames (default:sprite)--help, -h: Show help information
The tool generates the following files in the output directory:
sprite.png- Regular sprite sheetsprite@2x.png- Retina (2x) sprite sheetsprite.json- Metadata for regular sprite sheetsprite@2x.json- Metadata for retina sprite sheet
.
├── lib/
│ ├── spriteGenerator.js # Core sprite generation logic
│ ├── svgOptimizer.js # SVG optimization utilities
│ └── utils.js # Common utilities and logging
├── index.js # CLI entry point
└── package.json
fs-extra: Enhanced file system operationsglob: File pattern matchingpotpack: Rectangle packing algorithmsharp: Image processingspritesmith: Sprite sheet generationsvgo: SVG optimizationyargs: Command line argument parsing
MIT