SVG [icon] string styler for svelte
Svelte-Icon is a library that allows you to load, resize, and recolor SVG icons or images in Svelte. It is a suitable choice if you want to use a SVG icon package like Zondicons and Eva Icons. The library is also Typescript ready.
To install Svelte-Icon, you can follow the steps below:
SvelteKit:
import { svg } from "svelte-icong"
import Icon from "./path/to/Icon.svg"
const iconString = svg`${Icon}`
Rollup:
rollup-plugin-string.rollup-plugin-string package:npm install rollup-plugin-string --save-dev
rollup-plugin-string. For example:import { svg } from "svelte-icong"
import Icon from "./path/to/Icon.svg"
const iconString = svg`${Icon}`
Webpack:
raw-loader.raw-loader package:npm install raw-loader --save-dev
raw-loader. For example:import { svg } from "svelte-icong"
import Icon from "raw-loader!./path/to/Icon.svg"
const iconString = svg`${Icon}`
Sapper:
rollup.config.js is using the url plugin (modern sapper template), you need to disable it for icons used by this package (processed by the string plugin actually).plugins: [
replace({
preventAssignment: true,
"process.browser": true,
}),
svg({
/* options */
}),
url({
exclude: [
/\.svg$/,
],
/* options */
}),
/* other plugins */
]
Make sure to check out the example configuration provided by the library for a complete example of how to configure Svelte-Icon.
Svelte-Icon is a versatile library that makes it easy to load, resize, and recolor SVG icons or images in Svelte. With support for popular icon packages and Typescript integration, it offers a convenient solution for working with icons in your Svelte projects. The library provides clear installation instructions and configuration examples for different build tools, making it accessible to a wide range of developers.