vite-plugin-svg-sprite
vite-plugin-svg-sprite copied to clipboard
Option to customize export
Nice SVG plugin! Do you think you could add an option so that the module template could be changed?
In my case I'd like to export a ready-to-use Vue component, with a few bells and whistles attached, instead of just the SVD id.
Maybe a moduleTemplate(symbol: string, id: string)
option with the current template as default value?
const options = {
moduleTemplate(symbol, id) {
return `import addSymbol from 'vite-plugin-svg-sprite/es/runtime';
addSymbol(${symbol}, ${id});
export default ${id};`
}
}
It could be:
const options = {
moduleTemplate({
symbol, id, codeAddSymbol
}) {
return `${codeAddSymbol};
export default ${id};`
}
}
addSymbol
is an internal function and should not be exposed to users.
The tricky part is making sure import
are in the right position (I need to add some) but that would work as well.
This is an advanced scenario that's only present in one place (your build definition), so I wouldn't mind if I had to rewrite the template slightly after a major release.