SVG sprite plugin for Vite
npm i @remato/vite-plugin-svg-sprite -D
vite.config.js:
import createSvgSpritePlugin from '@remato/vite-plugin-svg-sprite';
const config = {
plugins: [
createSvgSpritePlugin({
symbolId: 'icon-[name]-[hash]',
}),
],
}
app code:
import appIconId from './path/to/icons/app.svg';
// react or vue component, as you want
export default function App() {
return (
<svg>
<use
xlinkHref={`#${appIconId.id}`}
/>
</svg>
);
}
const plugin = createSvgSpritePlugin(options);
For generating the id
attribute of <symbol>
element. Defaults to [name]
Match files that will be transformed. Defaults to '**.svg'
. See micromatch for the syntax document.
Enable SVGO for optimizing SVG. Defaults to true
.