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

ember-inline-svg

v1.0.1

Published

Ember CLI addon to render SVG images inline

Downloads

33,260

Readme

ember-inline-svg

CI

Displays SVG images inline.

Compatibility

  • Ember.js v3.4 or above
  • Ember CLI v2.13 or above
  • Node.js v8 or above

Installation

ember install ember-inline-svg

Usage

{{inline-svg "path/to/file"}}

This will display the SVG found at /public/path/to/file.svg (see below on how to change this).

You can specify a class for the element like so:

{{inline-svg "my-svg" class="foo"}}

Also, you can add/update <title></title> by doing:

{{inline-svg 'mySVG' title="myTitle"}}
{{inline-svg 'mySVG' class="myClass" title="myTitle"}}

Configuring

SVG Paths

By default the addon expects to find your SVG images at /public/, but you can change this by setting the svg.paths option in your application's ember-cli-build.js like so:

var app = new EmberApp({
  svg: {
    paths: [
      'public/images',
      'app/svgs'
    ]
  }
});

Optimizing

SVGs are optimized by svgo by default.

You can configure this by setting the svg.optimize options:

var app = new EmberApp({
  svg: {
    optimize: {
      plugins: [
        { removeDoctype: false },
        { removeTitle: true },
        { removeDesc: true }
      ]
    }
  }
});

Please bear in mind that but default we are stripping title from any svg with removeTitle: true, you can disable it with removeTitle: false or alternatively, you can disable every optimization by doing:

var app = new EmberApp({
  svg: {
    optimize: false
  }
});

Custom Plugins

SVGO now supports custom plugins.

See SVGO's plugins for examples on what you can do.

Eg, here's how you could strip IDs from all elements:

var app = new EmberApp({
  svg: {
    optimize: {
      plugins: [
        {
          myCustomPlugin: {
            type: "perItem",
            fn: function(item) {
              item.eachAttr(function(attr) {
                if (attr.name === 'id') {
                  item.removeAttr('id')
                }
              });
            }
          }
        }
      ]
    }
  }
});

Troubleshooting

Atrociously slow build times >:[

Longer build times have two main causes:

  • huge .svg files
  • lots of .svg files

You can easily run into this when using SVG fonts. By default ember-inline-svg processes all .svg files contained in the /public directory. If your fonts live somewhere inside that directory, e.g. /public/fonts, these files will be processed, although you will never use them (as inline SVGs).

A quick and easy fix is changing the svg.paths option in the configuration. Just explicitly list all directories with images that you want processed by ember-inline-svg.

If the longer build time is not caused by SVG fonts, but by actual SVG images that you actually need, you can turn off the optimization as a whole or individual plugins to remove or diminish another time-consuming build step.

Currently the caching does not work as expected. The bug is tracked in issue #15. We are positive, that fixing this bug will speed up the builds.

No SVG found / The Handlebars template is not rendered

If you switch to a route that contains an {{inline-svg}} helper and nothing is displayed, like really nothing, then this is caused by a failed assertion. Open the Dev Tools and you will see something like this:

Error: Assertion Failed: No SVG found for foo/bar/baz.svg

This happens, when you try to inline a non-exisent or wrongly addressed .svg file.

  1. Check the spelling.
  2. Make sure that your path is without a leading slash, e.g. foo/bar/baz.svg vs. /foo/bar/baz.svg.
  3. The path is always absolute and not relative to the current URL.
  4. public is not part of the path. So use foo.svg instead of /public/foo.svg.
  5. If you fiddled around with the svg.paths option, check the following:
  • The .svg file you're trying to inline is a direct or indirect child of any of the directories listed in svg.paths.
  • If the filename is something like /public/images/foo/bar.svg and your svg.paths option is set to something like ['public/images'], you have to address the image with foo/bar.svg, instead of the default images/foo/bar.svg.

Contributing

See the Contributing guide for details.

License

This project is licensed under the MIT License.