1.0.1 • Published 3 years ago
@meludi/sprite-it v1.0.1
@meludi/sprite-it
Combines multiple named SVG files into one sprite.svg using <symbol>.
Based on svgstore.
Install
$ npm i -D @meludi/sprite-itPrepare
Add the following file to your project root: .sprite-it.js:
module.exports = {
/**
* Default setup
*
*/
setup: {
inputDir: 'example/icons', // Path to your svg icons folder
outputDir: 'dist/public', // sprite.svg will be generated in this folder
spriteName: 'sprite.svg', // Name of your generated sprite.svg
},
/**
* Default presets
*
* Check out
* {@link https://github.com/svg/svgo SVGO} and
* {@link https://github.com/svg/svgo#default-preset SVGO default-preset}.
*/
presets: {
minifyStyles: true,
removeUselessDefs: true,
removeNonInheritableGroupAttrs: true,
removeTitle: true,
cleanupAttrs: true,
removeMetadata: true,
removeDoctype: true,
removeXMLProcInst: true,
collapseGroups: true,
},
};It is also recommended to add the following script to your package.json for easy usage:
"scripts": {
"sprite-it": "sprite-it"
}Usage
Run it
$ npm run sprite-itUse it
<svg role="img">
<use xlink:href="/outputDir/sprite.svg#name-of-your-svg-icon"></use>
</svg>Example
CLI
Use --record or -r to map and compare generated icons. The mapping is saved to the file .sprite-it.manifest.json.
Use --manifest your-manifest-file.json or -m your-manifest-file.json to override the default file name .sprite-it.manifest.json.
More options
$ npm run sprite-it -- --help