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

svg-as-symbol-loader

v1.2.4

Published

A webpack loader which loads SVG file contents as SVG <symbol> element markup.

Downloads

1,800

Readme

svg-as-symbol-loader

NPM version NPM downloads codecov MIT License

A webpack loader which wraps content of root element of source SVG file inside <symbol> element and returns resulting markup.

What loader does

It takes contents of root element in source SVG markup (usually, root element will be <svg>), wraps it into <symbol> tag and returns resulting markup.
It is possible to use another tag instead of <symbol> using tag loader parameter.
Attributes applied to root element in source SVG file will be preserved and applied to target <symbol> tag.
If source SVG image contains elements with id attribute set, loader will append unique prefix to all ids in order to make them unique in the universe.

Why do I need this?

There may be different usage scenarios for different people. One of them is described below.

Usually data:URI scheme is used to embed icons in SVG file. That results in SVG file containing urls with data:URI scheme.
Although support for such url scheme is pretty good, some SVG parsers do not understand such urls. For example, Apache Batik fails to rasterize SVG markup including urls with data:URI to PDF.
If embedded icon is SVG itself, it can be included by copy/pasting its markup into target SVG file. In order to point to inserted element, it should have an id attribute assigned, which can be assigned using id loader parameter.

Supported parameters

The loader supports the following parameters:

tag

Defaults to symbol. Is used as the name of root tag in generated SVG markup.

id

If given, will be applied to the root tag (symbol by default, see description for tag option) in generated SVG markup.

class

If given, will be applied to the root tag in generated SVG markup.

viewBox

If given, overwrites value of viewBox attribute applied to the svg tag in source SVG file.

height

If given, overwrites value of height attribute applied to the svg tag in source SVG file.

width

If given, overwrites value of width attribute applied to the svg tag in source SVG file.

preserveAspectRatio

If given, overwrites value of preserveAspectRatio attribute applied to the svg tag in source SVG file.

Parameters can be passed both in a url or from webpack config file. See Using loaders section in webpack documentation for more details.

The id and class parameters allow naming templates based on filename interpolation. See loader-utils#interpolatename for full usage details.

Usage

Documentation: Using loaders

License

MIT (http://www.opensource.org/licenses/mit-license.php)