Create an SVG Sprites using svgson and react
yarn add svg-spreact
const svgSpreact = require('svg-spreact')
const icons = [
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Add</title>
<path data-name="layer1"
fill="none" stroke="#202020" stroke-miterlimit="10" stroke-width="2" d="M32 16v32m16-16H16"
stroke-linejoin="round" stroke-linecap="round"></path>
</svg>`,
`<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" xmlns:xlink="http://www.w3.org/1999/xlink">
<title>Checkmark</title>
<path data-name="layer1"
fill="none" stroke="#202020" stroke-miterlimit="10" stroke-width="2" d="M16 33l11 11 21-22"
stroke-linejoin="round" stroke-linecap="round"></path>
</svg>`
]
svgSpreact(icons).then(({ defs, refs }) => {
console.log(defs) // <symbol>
console.log(refs) // <use>
})
svgSpreact(input, [options])
Type: Array
Type: Object
tidy
output prettyfied (Boolean
) default:true
optimize
output optimizde with svgo (Boolean
) default:true
svgoConfig
SVGO plugins configuration (Object
) defaultprocessId
function for customize Iconsid
s (Function
) default:(n) => 'Icon_' + n
className
classname/s to add on each<use>
element (String
) default: ''
Take a look into this example reading a folder with Icons
svg-spreact-cli CLI version