Installations
npm install vue-svg-icon-loader
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>= 6.0
Node Version
10.2.1
NPM Version
5.6.0
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
Developer
wadetandy
Download Statistics
Total Downloads
696,799
Last Day
498
Last Week
3,351
Last Month
11,268
Last Year
114,185
GitHub Statistics
24 Stars
40 Commits
2 Forks
3 Watching
2 Branches
1 Contributors
Bundle Size
44.89 kB
Minified
14.94 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.1.1
Package Id
vue-svg-icon-loader@2.1.1
Unpacked Size
7.48 kB
Size
3.72 kB
File Count
8
NPM Version
5.6.0
Node Version
10.2.1
Total Downloads
Cumulative downloads
Total Downloads
696,799
Last day
-25.6%
498
Compared to previous day
Last week
-21.6%
3,351
Compared to previous week
Last month
46.2%
11,268
Compared to previous month
Last year
20.9%
114,185
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
2
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:
1<template> 2 <div> 3 <my-icon width='1.5em' height='1.5em'/> 4 </div> 5</template> 6 7<script> 8import MyIcon from './my-icon.svg' 9 10export default { 11 components: { 12 MyIcon 13 }, 14} 15</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:
1 module.exports = { 2 entry: './app.js', 3 output: { 4 filename: 'bundle.js' 5 }, 6 module: { 7 rules: [ 8 // ... other configured loaders 9 { 10 test: /\.svg$/, 11 use: [ 12 'vue-svg-icon-loader', 13 ], 14 } 15 ] 16 } 17 }
Options
You an also provide options to the loader:
1{ 2 test: /\.svg$/, 3 use: [ 4 { 5 loader: 'vue-svg-icon-loader', 6 options: { 7 defaultScale: number | undefined 8 } 9 } 10 ] 11}
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:
1declare module "*.svg" { 2 import Vue from 'vue' 3 export default Vue 4}
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
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Score
3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to vue-svg-icon-loader
@yzfe/svgicon-loader
Webpack loader to load svg icon
@yzfe/vue-cli-plugin-svgicon
vue-cli plugin to add @yzfe/svgicon-loader config
vue-symbol-icon
A Vue SVG Symbol icon component for svg-sprite-loader, Easy to custom SVG icon 's color and size!!!
@aidol/svg-icon
A Vue SVG Symbol icon component for svg-sprite-loader, Easy to custom SVG icon 's color and size!!!