Last active
May 30, 2021 07:15
-
-
Save bluwy/948091babb28daafe5fbfdb50021b2ab to your computer and use it in GitHub Desktop.
Load SVGs as Svelte components with the least runtime overhead. Not sure if this actually improve performance?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default function sveltePreprocessSvg() { | |
return { | |
markup({ content }) { | |
content = content.trim() | |
if (content.startsWith('<svg ') && content.endsWith('</svg>')) { | |
return { code: `{@html \`${content}\`}` } | |
} else { | |
return { code: content } | |
} | |
}, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment