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

vue-svg-icon-loader

v2.1.1

Published

Turn SVG files into Vuejs Icon Components

Downloads

11,041

Readme

Vue SVG Icon Loader for webpack

This is a webpack loader that turns SVG icons into directly-importable vuejs components. You can import these and use them directly in your Vue applications:

<template>
  <div>
    <my-icon width='1.5em' height='1.5em'/>
  </div>
</template>

<script>
import MyIcon from './my-icon.svg'

export default {
  components: {
    MyIcon
  },
}
</script>

SVG attributes can be overridden with CSS or inline on the icon element in your template. See the example project for more usage examples.

Caveats

While the 1.x version of this project was originally designed to work with svg-sprite-loader, this was no longer necessary for my use-case and I found the loader only added complexity without offering a lot of benefit. If down the line other users want to take advantage of the sprite loader then I'm glad to add that back in as a possible configuration option, but it didn't make sense to support without knowing people were using it. The 1.x branch should still work for you, however

Getting Started

Examples

There is a sample Vue + Webpack project in the examples/ directory that shows how to use this in an application.

Installation

yarn add -D vue-svg-icon-loader

or

npm install --save-dev vue-svg-icon-loader

You will also need to add a runtime dependency on vue-svg-component-runtime: yarn add vue-svg-component-runtime

Configuration

Create or update webpack.config.js like so:

  module.exports = {
    entry: './app.js',
    output: {
      filename: 'bundle.js'
    },
    module: {
      rules: [
        // ... other configured loaders
        {
          test: /\.svg$/,
          use: [
            'vue-svg-icon-loader',
          ],
        }
      ]
    }
  }

Options

You an also provide options to the loader:

{
  test: /\.svg$/,
  use: [
    {
      loader: 'vue-svg-icon-loader',
      options: {
        defaultScale: number | undefined
      }
    }
  ]
}
defaultScale

default = 1

Setting this to an integer will multiply the SVG viewBox dimensions by this number in each component. This can be overridden per component instnace by passing a scale prop.

Typescript

Importing svg files as Vue components in typescript requires one additional setup step. You will need to provide a type definition for .svg files so that typescript knows to treat them as a vue component. If you haven't done this, you'll see typescript reporting "module not found" errors. Create a svg.d.ts file wherever you store external type defintions, and add the following content:

declare module "*.svg" {
  import Vue from 'vue'
  export default Vue
}

Note: If anyone knows a way for this loader to provide this for projects automatically, please open an issue and let me know!

Contributing

I want you to help make this even better. Please feel free to contribute; if you have any problems or feature suggestions, please open an issue on Github.

License

MIT License