Socket
Socket
Sign inDemoInstall

astro-svg-sprite

Package Overview
Dependencies
0
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    astro-svg-sprite

A zero-dependency Astro Integration that generates a `sprite.svg` from SVG files in your Astro project.


Version published
Maintainers
1
Install size
12.6 kB
Created

Changelog

Source

v1.1.0

Minor Changes

  • Updated emitFile:fasle Option, now embeds svg-sprite code in body section.

Readme

Source

Latest Updates! 🎉 See the change log for details.

stro-svg-sprite

A zero-dependency Astro Integration that generates a sprite.svg from SVG files in your Astro project.

Installation

This package is compatible with Astro 2.0 and above, which support the Integrations API.

To automate the installation, use the astro add command-line tool. You can initialize it via npx, yarn, or pnpm based on your preference.

npx astro add astro-svg-sprite

Alternatively, you can manually install it by running the following command in your terminal:

npm install astro-svg-sprite

Usage

Getting Started

Add astro-svg-sprite to your astro.config.* file:

// astro.config.mjs
import { defineConfig } from "astro/config";
import svgSprite from "astro-svg-sprite";

export default defineConfig({
  integrations: [svgSprite()],
});

Store the SVG files to be used for the generated sprite.svg in the src/assets/images/sprite directory.

/
├── astro.config.mjs
├── public
|   └── assets
|       └── images
|           └── sprite.svg
├── src
|   └── assets
|       └── images
|           └── sprite
|               └── 1.svg
|               └── 2.svg
|               └── *.svg
├── tsconfig.json
├── package.json

Generating the sprite.svg on build:

npm run dev

or

npm run build

The sprite.svg will be output to public/assets/images directory.

To use the generated sprite.svg file, create a Sprite component at components/Sprite.astro:

---
export interface props {
  name: string;
}

const { class:className, name } = Astro.props;
---
<svg class={className}>
  <use xlink:href=`${Astro.site}assets/images/sprite.svg#${name}`></use>
</svg>

Then call the Sprite.astro component on other pages.

---
import Sprite from 'components/Sprite.astro'
---
<Sprite name="fileName" class="customClassName"/>
Advanced

Here is an example of an advanced full configuration. With the help of JSDoc, you can easily configure it.

// astro.config.mjs
import { defineConfig } from "astro/config";
import svgSprite from "astro-svg-sprite";

export default defineConfig({
  integrations: [
    svgSprite({
      mode: "verbose",
      include: [
        "./src/assets/images/sprite",
        "./src/assets/images",
        "./src/assets",
      ],
      emitFile: {
        compress: "standard",
        path: "assets/images",
      },
    }),
  ],
});

Note: emitFile.compress recommends using the default standard mode. The best mode will convert some svg tags into path tags.

Need Help or Feedback?

Submit your issues or feedback on our GitHub channel.

Changelog

See CHANGELOG.md for a history of changes to this Integration.

Keywords

FAQs

Last updated on 30 Sep 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc