SVG sprite plugin for Vite2
npm i plugin-svg-sprite -D
vite.config.js:
import svgSprite from 'plugin-svg-sprite';
const config = {
plugins: [svgSprite()],
};
app code:
const modules = import.meta.globEager('./assets/icons/svg/*.svg');
console.log(modules);
// or
import appIconId from './path/to/icons/app.svg';
// react or vue component, as you want
export default function App() {
return (
<svg>
<use xlinkHref={`#${appIconId}`} />
</svg>
);
}