jasikpark / astro-svg-loader

Import SVG's as Astro components

Home Page:https://stackblitz.com/github/jasikpark/astro-svg-loader/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

@jasikpark/astro-svg-loader

FOSSA Status

This package allows you to import SVGs as Astro components, using @natemoo-re's ultrahtml and vite's support for raw imports to do the trick.

Taking inspiration from https://css-tricks.com/pretty-good-svg-icon-system/ that holds that icons should always be inlined.

Usage:

Peer deps are astro

npm add -D @jasikpark/astro-svg-loader
yarn add -D @jasikpark/astro-svg-loader
pnpm add -D @jasikpark/astro-svg-loader

then in an Astro component:

---
import Svg from "@jasikpark/astro-svg-loader";
---

<Svg
  src={import("@assets/my-cool-illustration.svg?raw")}
  aria-label="Cool illustration of an abstract nebula"
/>

Be sure to use a raw import: ?raw, or you'll import the URL rather than the SVG source.

Open in StackBlitz

License

FOSSA Status

Inspiration

About

Import SVG's as Astro components

https://stackblitz.com/github/jasikpark/astro-svg-loader/

License:MIT License


Languages

Language:TypeScript 61.6%Language:Astro 30.7%Language:JavaScript 7.7%