npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

astro-svgs

v1.1.3

Published

A compact solution for SVG sprites in Astro projects. It automates symbol ID management, supports hot reloading, and generates optimized SVG sprites with minimal setup—ideal for seamless SVG icon integration.

Downloads

292

Readme

Overview

NPM Version Build Status

A compact, flexible solution for managing SVG sprites in Astro projects.

It automates symbol ID management, supports hot reloading, and generates optimized SVG sprites with minimal setup. It includes built-in components and an open API, allowing easy customization to suit your needs.

Installation

Quickly install with the astro add command:

npx astro add astro-svgs

If you run into issues, try with Manual Setup guide.

Usage

Setup

  • Step 1: To install manually, run:

    npm install astro-svgs
  • Step 2: Add the integration to your Astro config file (astro.config.*):

    // @ts-check
    import { defineConfig } from "astro/config";
    import svgs from "astro-svgs";
    
    export default defineConfig({
      integrations: [svgs()],
    });
  • Step 3: Place your SVG files in the default src/svgs folder:

    /
    ├── src/
    │   ├── pages/
    │   │   └── index.astro
    │   └── svgs/
    │       ├── a.svg
    │       ├── b.svg
    │       └── *.svg
    └── package.json
  • Step 4: Use the built-in Icon.astro component to render icons from the sprite:

    ---
    import Layout from '~/Layouts/Layout.astro';
    import { Icon } from 'astro-svgs/Icon.astro';
    ---
    <Layout>
      {/* Type hints and checks are provided by `.astro/integrations/astro-svgs/types.d.ts`. */}
      <Icon name="a" class="<CustomClassName>" />
    </Layout>

Live Access

Start the server with npm run dev, then access the virtual sprite.svg at http://localhost:4321/@svgs/sprite.svg.

Integration API

Full configuration reference

// @ts-check
import { defineConfig } from "astro/config";
import svgs from "astro-svgs";

export default defineConfig({
  build: {
    assets: "_astro",
    // assetsPrefix: env.SITE_URL,
  }
  integrations: [
    svgs({
      /**
       * Folder paths containing SVG files to generate `sprite.svg`
       * @default "src/svgs"
       */
      input: ["src/assets/sprites", "src/assets/icons"],
      /**
       * @default
       * isDev ? "beatfify" : "high"
       */
      compress: "beautify",
    }),
  ],
});

Output: The sprite file will automatically be built in config.build.assets during the build process (e.g., _astro/sprite.43a97aac.svg).

Component API

file

type: string the sprite.svg file path.

SymbolId

type: Union Type The svg file unique name you should use.

Eg1: src/components/Icon.astro

Creating a simple custom Icon.astro using the component API.

---
import { file, type SymbolId } from 'virtual:astro-svgs';
export interface Props {
    name: SymbolId;
}

const { name } = Astro.props;
---
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false">
    <use xlink:href={`${file}#${name}`} xmlns:xlink="http://www.w3.org/1999/xlink" />
</svg>

The virtual module definition is automatically generated when the server starts with npm run dev and is located at .astro/integrations/astro-svgs/types.d.ts.

Need help or Feedback?

If you have questions or feedback, feel free to submit an issue on our GitHub repository.

Changelog

For the full changelog, see the Releases page.

License

MIT