1
0
Fork 0
mirror of https://github.com/Findus23/RainbowRoad.git synced 2024-09-16 12:33:51 +02:00

improve SVG vite plugin

This commit is contained in:
Lukas Winkler 2023-02-28 22:48:19 +01:00
parent 0b0ff5eb69
commit 71ad1b984f
Signed by: lukas
GPG key ID: 54DE4D798D244853

View file

@ -12,13 +12,15 @@ function svgToDataURL(svgStr: string): string {
function customSvgLoader() {
return {
enforce: "pre",
name: 'vite-svg-patch-plugin',
transform: function (code, id) {
if (id.endsWith('.svg')) {
const extractedSvg = readFileSync(id, 'utf8');
return `export default '${svgToDataURL(extractedSvg)}'`;
load: function (id: string): null | string {
if (!id.endsWith('.svg')) {
return null
}
return code;
const extractedSvg = readFileSync(id, 'utf8');
return `export default '${svgToDataURL(extractedSvg)}'`;
}
} as Plugin;
}