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

@maddsua/svgbundler

v1.6.5

Published

Bundles separate .svg images to a single .css file

Downloads

2

Readme

svgbundler | The old C version is here

Basically, it takes a bunch of vector images and embedds them into single .css file.

We do that so our apps don't make hundreds of http requests just to load UI icons.

Just like this:

background-image: url(/test/src/svgs/map-marker.svg)

... becomes ...

background-image: url("data:image/svg+xml...");

How to use

  1. Install

    npm i @maddsua/svgbundler

  2. Place your .svg images somewhere in projects directory

  3. Use cli or add as an npm script:

    svgbundler -m -f /test/src/form:test/public/ui.css test/style.css:test/public/style.css

    In detail:

    1. /test/svgs/:test/public/ui.css

      will find all the svg files in the /test/svgs/ and bundle them to test/public/ui.css.

      Now just add classes to html, instead of adding background images via css.

    2. "test/style.css:test/public/style.css"

      will find all the references to .svg files in "test/style.css", load, minify and bundle them to "test/public/style.css".

      Essentially, it will replace url('/path/icon.svg') with url("data:image/svg+xml,%3C%3Fxml%2....")

    Note that paths are relative, / will resolve to the directory, from which nodejs was called, being project root in most cases.

NEW:

You can now specify files directly in package.json:

...
"svgbundler": {
    "files": [
        {
            "from": "test/assets",
            "to": "test/public/countries.css",
            "override": true,
            "prefix": "ccode",
            "selector": "valid"
        }
    ]
}
...

Or in svgbundler.json:

{
	"files": [...]
}

Flag arguments

  1. --minify | -m : Remove unnecessary meta attributes from svg

  2. --flatten | -f : Replace dashes with underscores,

    like here: "dir/file-one.svg" --> ".dir-file_one"

  3. --prefix=[prefix] : Add a prefix css class. Adding 'ui-' will result in '.ui-image...'

  4. --watch | -w : Watch for file changes

  5. --silent | -s : Don't list all the input files, silent mode

  6. --package | -p : Load files from the package.json (format specified above)

  7. --config | -c : Load files from the svgbundler.config.json


See tests directory for more

📂 tests here

npm test command is also available

...and a screenshot of it working in watch mode as a cherry on top: