0.5.0 • Published 9 months ago

@mcansh/vite-svg-sprite-plugin v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

@mcansh/vite-svg-sprite-plugin

this vite plugin will transform any imported svg files and combine them into an svg sprite sheet

installation and set up

  npm i -D @mcansh/vite-svg-sprite-plugin

this is an example using Remix, but this plugin should work everywhere else as well

import { createSvgSpritePlugin } from "@mcansh/vite-svg-sprite-plugin";
import { vitePlugin as remix } from "@remix-run/dev";
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
  plugins: [remix(), tsconfigPaths(), createSvgSpritePlugin()],
});

you can configure the generated sprite file name as well as the generated symbol id pattern

import { createSvgSpritePlugin } from "@mcansh/vite-svg-sprite-plugin";

createSvgSpritePlugin({
  spriteOutputName: "sprite.svg",
  symbolId: "icon-[name]-[hash]",
});

usage

import spriteUrl from "virtual:@mcansh/vite-svg-sprite-plugin";
import linkIconHref from "@primer/octicons/build/svg/link-16.svg";
import type { LinksFunction } from "@remix-run/node";

export const links: LinksFunction = () => {
  return [
    { rel: "preload", as: "image", href: spriteUrl, type: "image/svg+xml" },
  ];
};

export default function Component() {
  return (
    <svg className="size-4" aria-hidden>
      <use href={linkIconHref} />
    </svg>
  );
}
0.5.0

9 months ago

0.4.2

1 year ago

0.4.0-pre.0

1 year ago

0.4.0-pre.1

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.3.0

1 year ago

0.2.0

1 year ago

0.1.6

1 year ago

0.1.5

1 year ago

0.1.4

1 year ago

0.1.3

1 year ago

0.1.2

1 year ago

0.1.2-pre.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago