All Projects → wadetandy → vue-svg-icon-loader

wadetandy / vue-svg-icon-loader

Licence: MIT license
Turn SVG files into VueJS Components

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to vue-svg-icon-loader

font-gis
Icon font and SVG for use with GIS and spatial analysis tools
Stars: ✭ 121 (+404.17%)
Mutual labels:  svg-icons, svg-sprites
ionicons-sprite
SVG sprite icon set based on Ionicons icons
Stars: ✭ 22 (-8.33%)
Mutual labels:  svg-icons, svg-sprites
webpack-svg-sprite-sample
a webpack SVG sprite sample when using Vue and React
Stars: ✭ 19 (-20.83%)
Mutual labels:  svg-icons, svg-sprites
Feathericon
simply generic vector icon collection - including sketch file, svg files, and font files.
Stars: ✭ 178 (+641.67%)
Mutual labels:  svg-icons, svg-sprites
Coreui Icons
CoreUI Free Icons - Premium designed free icon set with marks in SVG, Webfont and raster formats
Stars: ✭ 1,813 (+7454.17%)
Mutual labels:  svg-icons, svg-sprites
Svg Icon
An ultimate SVG icons collection DONE RIGHT, with over 10,000 SVG icons out of the box.
Stars: ✭ 870 (+3525%)
Mutual labels:  svg-icons, svg-sprites
react-crud-icons
57 SVG icons for CRUD applications, packaged as a React component with light & dark themes and tooltip.
Stars: ✭ 19 (-20.83%)
Mutual labels:  svg-icons, svg-sprites
svgpack
A tool for generating and managing SVG Sprites.
Stars: ✭ 28 (+16.67%)
Mutual labels:  svg-icons, svg-sprites
Svgsprit.es
Public endpoint to generate SVG Sprites
Stars: ✭ 73 (+204.17%)
Mutual labels:  svg-icons, svg-sprites
Svgeez
A Ruby gem for automatically generating an SVG sprite from a folder of SVG icons.
Stars: ✭ 69 (+187.5%)
Mutual labels:  svg-icons, svg-sprites
Font Awesome
The iconic SVG, font, and CSS toolkit
Stars: ✭ 66,937 (+278804.17%)
Mutual labels:  svg-icons, svg-sprites
flexicon
SVG icon collection.
Stars: ✭ 23 (-4.17%)
Mutual labels:  svg-icons, svg-sprites
Supertinyicons
Under 1KB each! Super Tiny Icons are miniscule SVG versions of your favourite website and app logos
Stars: ✭ 13,177 (+54804.17%)
Mutual labels:  svg-icons
sass-inline-svg
Inline url-encoded SVG with Sass. Optional variable string replacement included!
Stars: ✭ 21 (-12.5%)
Mutual labels:  svg-icons
Weather Underground Icons
Weather Underground Icons ( PNG & SVG )
Stars: ✭ 186 (+675%)
Mutual labels:  svg-icons
blade-bootstrap-icons
A package to easily make use of Bootstrap Icons in your Laravel Blade views
Stars: ✭ 46 (+91.67%)
Mutual labels:  svg-icons
vue-feather-icon
No description or website provided.
Stars: ✭ 109 (+354.17%)
Mutual labels:  svg-icons
Akar Icons
A perfectly rounded icon library made for designers, developers, and pretty much everyone.
Stars: ✭ 184 (+666.67%)
Mutual labels:  svg-icons
File Icon Vectors
A collection of file type icons in SVG format
Stars: ✭ 171 (+612.5%)
Mutual labels:  svg-icons
Webfont
Awesome generator of webfont
Stars: ✭ 170 (+608.33%)
Mutual labels:  svg-icons

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].