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

sveltekit-sprite

v0.1.2

Published

The plugin inline SVG into SvelteKit app template

Downloads

133

Readme

SvelteKit Sprite Plugin

The plugin compiles svg files into a sprite and inline as string to the app template.

  • Sprite with symbols from svg files
  • Uniq id links in symbols
  • Uniq id's for all symbols
  • Folder based id's
  • Sprite as string in app.html
  • SVGO for sprite optimization

Roadmap

☑︎  Build sprite from folder ☑︎  Style id encapsulating □  Build sprite from files array □  Error handling □  File watcher □  Save sprite to file □  Unwrap symbols from file in folder □  Add svg's from @import

Get started

1. Install the plugin Run npm i -D sveltekit-sprite command.

2. Edit Vite config Import and configure the plugin in the vite.config.js file:

  import { sveltekit } from '@sveltejs/kit/vite';
+ import { sveltekitSprite } from 'sveltekit-sprite';

  /** @type {import('vite').UserConfig} */
  const config = {
    plugins: [
+   sveltekitSprite({…option here}),
      sveltekit()
    ],
  };

3. Add label to app template In app.html add label %vite.plugin.sprite% to point Vite where to inline the svg sprite. You can change label by injectLabel option.

  <body data-sveltekit-preload-data="hover">
+   %vite.plugin.sprite%
    <div style="display: contents">%sveltekit.body%</div>
  </body>

4. Put your svg files to ./src/lib/sprite/ You can change sprite folder by svgSource option.

5. Run app npm run dev ⚠️ For now sprite will compile once on start app in dev mode or on build. If you want add more symbols to sprite → restart the app.

6. Add link to the specific symbol on your page Symbols id's will begin with the prefix svg--[subfolder]-[file-name] You can change symbol prefix by symbolPrefix option.

<svg>
  <use xlink:href="#svg--icon" />
</svg>

Options

Default option are presented.

svgoOptions

See SVGO config info on official repo Additional option presetDefault for disable default plugins ⚠️ If you pass your own presetDefault preset, Svelte-sprite will disable the cleanupIDs option and add the removeViewBox: false option to build the sprite from folder.

⚠️ prefixIds option is always on for build a sprite from a folder with the: prefix option, you can't override it.

sveltekitSprite({
  svgoOptions: {
    presetDefault: true,
    ... other option here
  },
}),

svgSource

You can use it in two ways: Path to ready sprite file On this mode you can optimize your sprite by SVGO options. The symbols id will leave as they are.

Path to folder with svg's files (from project root) On this mode sprite folder structure represent symbols id as folders router in SveleKit represent addresses of app. For example: /sprite/icons/star.svg → become → #svg--icons-star

sveltekitSprite({
  svgSource: 'src/lib/sprite',
}),

symbolPrefix

From the prefix begin all id of symbols: [symbolPrefix]--[subfolder]-[file-name]

sveltekitSprite({
  symbolPrefix: 'svg',
}),

stylePrefix

All id's in the svg files will be replaced by he prefix and file name: [stylePrefix]--[subfolder]-[file-name]

sveltekitSprite({
  stylePrefix: 'svg-style',
}),

injectLabel

Label in the app.html template to place the sprite string.

sveltekitSprite({
  injectLabel: '%vite.plugin.sprite%',
}),