Installations
npm install vue-svg-inline-loader
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
16.15.1
NPM Version
8.13.1
Score
69.3
Supply Chain
96.3
Quality
73.6
Maintenance
50
Vulnerability
98.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
oliverfindl
Download Statistics
Total Downloads
2,912,679
Last Day
1,200
Last Week
5,053
Last Month
21,292
Last Year
344,527
GitHub Statistics
124 Stars
207 Commits
18 Forks
3 Watching
2 Branches
6 Contributors
Bundle Size
0.97 MB
Minified
274.44 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.1.5
Package Id
vue-svg-inline-loader@2.1.5
Unpacked Size
28.38 kB
Size
9.11 kB
File Count
7
NPM Version
8.13.1
Node Version
16.15.1
Total Downloads
Cumulative downloads
Total Downloads
2,912,679
Last day
23.2%
1,200
Compared to previous day
Last week
-19.3%
5,053
Compared to previous week
Last month
-6.6%
21,292
Compared to previous month
Last year
-35%
344,527
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
Dev Dependencies
1
vue-svg-inline-loader
Webpack loader used for inline replacement of SVG images with actual content of SVG files in Vue projects.
Loader parses only HTML template format.
Loader has built-in SVGO support for SVG optimization.
Sprite option works only with Vue Single File Component approach.
Vue CLI
Vue 3 projects created via Vue CLI aren't built on top of Webpack, they use Vite (which is build on top of Rollup) instead. In this case, this loader won't work. Please take a look at vue-svg-inline-plugin, which works similar to this loader.
Notable changes
- v2.1.4
- Added Nuxt module
- v2.1.0
- Added new option: cloneAttributes
- v2.0.0
- Removed transpiled version
- Removed core-js@2 dependency
- Recreated all examples (except vanilla Webpack one) with up-to-date CLIs
- v1.5.0
- Added new option: transformImageAttributesToVueDirectives
- Added new option: verbose
- v1.4.4
- Updated order of attributes operations
- v1.4.0
- Added new option: addTitle
- Fixed issue with lowercase-ing attribute values
- v1.3.1
- Hotfixed issue with doubled attribute definitions on SVG node. This may introduce breaking changes for developers who used image definitions outside of template tag.
- v1.3.0
- Added new option: addAttributes
- v1.2.17
- Add example usage configuration for laravel-mix based projects
- v1.2.16
- Added example for quasar based projects
- v1.2.14
- Added example for gridsome based projects
- v1.2.11
- Fixed a bug where original svg attributes were used by referencing svg rather than symbol itself. This may introduce breaking changes for developers who rely on this bugged behavior.
- v1.2.6
- Modified default value of svgo option to preserve viewBox attribute
- Modified svgo option to accept
true
value as alias for default configuration
- v1.2.5
- Modified svgo option to accept
null
orfalse
value for disabling SVG optimization
- Modified svgo option to accept
- v1.2.3
- v1.2.0
- Upgraded Babel to version 7
- Refactored code to ES6 syntax
- Added new option: dataAttributes
- Options are now deep-merged
- v1.1.3
- Added transpiled version of loader
- v1.1.0
- Added new option: md5
- v1.0.8
- Options structure changed, deprecated options still get parsed to new ones
- v1.0.0
- Initial release based on my img-svg-inline-loader project
Install
1$ npm install vue-svg-inline-loader --save-dev
1$ yarn add vue-svg-inline-loader --dev
Usage
With webpack - webpack.config.js (recommended):
1// webpack 2 3module.exports = { 4 module: { 5 rules: [ 6 { 7 test: /\.vue$/, 8 use: [ 9 { 10 loader: "vue-loader", 11 options: { /* ... */ } 12 }, 13 { 14 loader: "vue-svg-inline-loader", 15 options: { /* ... */ } 16 } 17 ] 18 } 19 ] 20 } 21};
With vue-cli - vue.config.js:
With gridsome - gridsome.config.js:
With quasar - quasar.conf.js:
1// vue-cli, gridsome, quasar 2 3module.exports = { 4 chainWebpack: config => { 5 config.module 6 .rule("vue") 7 .use("vue-svg-inline-loader") 8 .loader("vue-svg-inline-loader") 9 .options({ /* ... */ }); 10 } 11};
With nuxt - nuxt.config.js:
1// nuxt 2 3module.exports = { 4 buildModules: [ 5 [ "vue-svg-inline-loader/nuxt", { /* options */ } ] 6 ], 7 // or 8 buildModules: [ "vue-svg-inline-loader/nuxt" ], 9 vueSvgInlineLoader: { 10 /* options */ 11 } 12};
With quasar - quasar.conf.js:
1// quasar 2 3module.exports = { 4 build: { 5 extendWebpack(config) { 6 const vueRule = config.module.rules.find(({ test }) => test.toString() === /\.vue$/.toString()); 7 vueRule.use.push({ 8 loader: "vue-svg-inline-loader", 9 options: { /* ... */ } 10 }); 11 } 12 } 13};
With laravel-mix - webpack.mix.js:
1// laravel-mix 2 3const mix = require("laravel-mix"); 4 5mix.override(config => { 6 config.module.rules.push({ 7 test: /\.vue$/, 8 use: [{ 9 loader: "vue-svg-inline-loader", 10 options: { /* ... */ } 11 }] 12 }) 13});
Basic inline SVG usage with svg-inline
keyword directive:
1<img svg-inline class="icon" src="./images/example.svg" alt="example" />
Which replaces into:
1<svg xmlns="http://www.w3.org/2000/svg" viewBox="..." svg-inline role="presentation" focusable="false" tabindex="-1" class="icon"> 2 <path d="..."></path> 3</svg>
Basic inline SVG sprite usage with svg-sprite
keyword directive:
1<img svg-inline svg-sprite class="icon" src="./images/example.svg" alt="example" />
Which replaces into:
1<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="..." svg-inline svg-sprite role="presentation" focusable="false" tabindex="-1" class="icon"> 2 <use xlink:href="#svg-sprite-md5hash" href="#svg-sprite-md5hash"></use> 3</svg> 4<!-- ... --> 5<!-- will get injected right before root closing tag in Vue component --> 6<svg xmlns="http://www.w3.org/2000/svg" style="display: none !important;"> 7 <symbol id="svg-sprite-md5hash" xmlns="http://www.w3.org/2000/svg" viewBox="..."> 8 <path d="..."></path> 9 </symbol> 10 <!-- ... --> 11</svg>
Notice
Loader won't parse any images with Vue bindings used as src
attribute [more info].
If you need to preserve image tag (e.g. in comments), you can wrap it in hash (#
) or triple backtick (```
) characters.
Configuration
Default options:
1{ 2 inline: { 3 keyword: "svg-inline", 4 strict: true 5 }, 6 sprite: { 7 keyword: "svg-sprite", 8 strict: true 9 }, 10 addTitle: false, 11 cloneAttributes: ["viewbox"], 12 addAttributes: { 13 role: "presentation", 14 focusable: false, 15 tabindex: -1 16 }, 17 dataAttributes: [], 18 removeAttributes: ["alt", "src"], 19 transformImageAttributesToVueDirectives: true, 20 md5: true, 21 xhtml: false, 22 svgo: true, 23/* value true for svgo option is alias for: 24 svgo: { 25 plugins: [ 26 { 27 removeViewBox: false 28 } 29 ] 30 }, 31*/ 32 verbose: false 33}
Explanation:
-
inline.keyword:
Defines keyword, which marks images you want to replace with inline SVG. Keyword has to be wrapped with whitespace characters (e.g. space). In case of some conflicts, you can also use data version of your keyword (e.g.data-keyword
). -
inline.strict:
In strict mode loader replaces only images with defined keyword. If strict mode is disabled, loader replaces all images. -
sprite.keyword:
Defines keyword, which marks images you want to replace with inline SVG using inline sprites. Keyword has to be wrapped with whitespace characters (e.g. space). In case of some conflicts, you can also use data version of your keyword (e.g.data-keyword
). -
sprite.strict:
In strict mode loader replaces only images with defined keyword. If strict mode is disabled, loader replaces all images. -
addTitle:
Transform imagealt
attribute into SVGtitle
tag, if not defined (removed with SVGO by default). This option has no effect while using inline SVG sprites. -
cloneAttributes:
Array of attributes which will be cloned into SVG link node while using inline SVG sprites. -
addAttributes:
Object of attributes which will be added. -
dataAttributes:
Array of attributes which will be renamed to data-attributes. -
removeAttributes:
Array of attributes which will be removed. -
transformImageAttributesToVueDirectives:
Transforms all non-Vue image tag attributes via Vuev-bind
directive. With this option enabled, Vue will handle merge / replace attributes, that are present on both resources - image tag and SVG tag. This might cause issues, when using Vue bindings on image tag attribute, that is also present on SVG tag (e.g.: class attribute). Please use verbose option for local debugging before submitting new issue. -
md5:
Use md5-encoded resource path as ID for inline SVG sprites instead of plaintext. Set it tofalse
only for development purposes. -
xhtml:
In XHTML mode attribute minimization is forbidden. Empty attributes are filled with their names to be XHTML-compliant (e.g.disabled="disabled"
). -
svgo:
Pass SVGO configuration object (documentation can be found here) ortrue
for default configuration. Passnull
orfalse
to disable SVG optimization. -
verbose:
Will print image tag, SVG tag and modified SVG tag (with attributes from image tag) for debugging purposes.
Notices
- User-defined options are deep-merged with default options. Arrays are not concatenated.
Examples
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 1/28 approved changesets -- score normalized to 0
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
project is not fuzzed
Details
- Warn: no fuzzer integrations found
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
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 3 are checked with a SAST tool
Score
3
/10
Last Scanned on 2025-01-20
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-inline-loader
vue-svg-sprite-loader
Webpack loader that takes a sprite svg and return a Vue component with the svg inline as template that can be imported
inline-vue-svg-loader
a loader for webpack to inline svg
vue-svg-inline-loader-corejs3
Webpack loader used for inline replacement of SVG images with actual content of SVG files in Vue projects.
vue-loader-svg-inliner
Webpack Loader to add simple inline svg support to vue.js single file component