vue-svgicon
A tool to create svg icon components. (vue 2.x)
This is a fork of https://github.com/MMF-FE/vue-svgicon with TypeScript support. Created this package temporarily till the PR on the original is accepted and merged.
Currently at https://www.npmjs.com/package/vue-svgicon-ts
Inspiration
https://github.com/Justineo/vue-awesome
demo
https://mmf-fe.github.io/vue-svgicon/
Usage
Generate icon
Install
# install global npm install vue-svgicon -g# install for project npm install vue-svgicon --save-dev
Command
# generate svg icon components vsvg -s /path/to/svg/source -t /path/for/generated/components
Use as npm scripts
# bash npm run svg
It will generate icons to the specified path.
Custom icon content format
# specify template path vsvg -s /path/to/svg/source -t /path/for/generated/components --tpl /path/for/icon-template
Default template is:
var icon = icon
TypeScript Support
# Add the typescript flag '--ts' vsvg -s /path/to/svg/source -t /path/for/generated/components --ts
This will cause the icon files generated as well as the index
file to be TypeScript files for use in those projects.
Colored Icons
In the cases were you have an SVG Logo which already has color and strokes, then to be able to retain that information in the bundled SVG, just be sure to end the filename with -color
;
Example: company-logo-color.svg
This file will retain the fills and stroke from the SVG file.
Use generated icon
Use plugin
// main.js // Default tag name is 'svgicon'Vue el: '#app'
Use icon in component
<!-- App.vue -->
You can import all icons at once
Props
icon
icon name
dir
The direction of icon. Default value is right
fill
Whether to fill the path/shape. Default value is true
You can use r-color to reverse the fill property
<!-- the first one is fill(default), the second use stroke --><!-- the first one is stoke, the second is fill -->
width / height
Specify the size of icon. Default value is 16px / 16px. Default unit is px
Color
Specify the color of icon. Default value is inherit.
If the icon is mutil path/shape, you can use mutil color. It is defined in the order of path/shape.
Also, you can use CSS to add colors.
You can't use this feature in scoped block.
Use gradient
Multiple directory (Namespace)
You can use multiple directory to discriminate the icons which has the same name.
├── arrow.svg
├── sora
│ ├── arrow.svg
│ └── fit
│ └── arrow.svg
Work on server-side render (SSR)
The component will insert the CSS style to the document object, so it will throw an error in SSR. The solution is to define an alias for vue-svgicon module if you use webpack.
var config = module: resolve: alias: 'vue-svgicon$': 'vue-svgicon/component/svgicon.vue'
If you are using other build systems..., I think you can find a similar solution to how webpack does it.
Work on IE
This component doesn't work on IE because IE don't support innerHTML
in SVGElement. You can use this polyfill to make it work. https://github.com/dnozay/innersvg-polyfill