mirror of
https://github.com/Findus23/RainbowRoad.git
synced 2024-09-19 16:03:52 +02:00
improve SVG vite plugin
This commit is contained in:
parent
0b0ff5eb69
commit
71ad1b984f
1 changed files with 7 additions and 5 deletions
|
@ -12,13 +12,15 @@ function svgToDataURL(svgStr: string): string {
|
||||||
|
|
||||||
function customSvgLoader() {
|
function customSvgLoader() {
|
||||||
return {
|
return {
|
||||||
|
enforce: "pre",
|
||||||
name: 'vite-svg-patch-plugin',
|
name: 'vite-svg-patch-plugin',
|
||||||
transform: function (code, id) {
|
load: function (id: string): null | string {
|
||||||
if (id.endsWith('.svg')) {
|
if (!id.endsWith('.svg')) {
|
||||||
const extractedSvg = readFileSync(id, 'utf8');
|
return null
|
||||||
return `export default '${svgToDataURL(extractedSvg)}'`;
|
|
||||||
}
|
}
|
||||||
return code;
|
const extractedSvg = readFileSync(id, 'utf8');
|
||||||
|
return `export default '${svgToDataURL(extractedSvg)}'`;
|
||||||
|
|
||||||
}
|
}
|
||||||
} as Plugin;
|
} as Plugin;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue