mirror of
https://github.com/Findus23/RainbowRoad.git
synced 2024-09-18 14:53:51 +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() {
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue