Skip to content

Instantly share code, notes, and snippets.

@bluwy
Last active May 30, 2021 07:15
Show Gist options
  • Select an option

  • Save bluwy/948091babb28daafe5fbfdb50021b2ab to your computer and use it in GitHub Desktop.

Select an option

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?
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