Installations
npm install vue-svg-inline-loader-corejs3
Developer Guide
Typescript
No
Module System
CommonJS
Node Version
14.0.0
NPM Version
6.14.4
Score
57.1
Supply Chain
95.3
Quality
72.6
Maintenance
50
Vulnerability
99.3
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
u1-liquid
Download Statistics
Total Downloads
20,248
Last Day
1
Last Week
6
Last Month
13
Last Year
117
GitHub Statistics
169 Commits
1 Watching
1 Branches
1 Contributors
Bundle Size
910.85 kB
Minified
261.29 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.5.0
Package Id
vue-svg-inline-loader-corejs3@1.5.0
Unpacked Size
41.96 kB
Size
12.48 kB
File Count
8
NPM Version
6.14.4
Node Version
14.0.0
Total Downloads
Cumulative downloads
Total Downloads
20,248
Last day
0%
1
Compared to previous day
Last week
100%
6
Compared to previous week
Last month
62.5%
13
Compared to previous month
Last year
-17.6%
117
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
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.
Notable changes
- 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:
With quasar - quasar.conf.js:
1// nuxt, quasar 2 3module.exports = { 4 build: { 5 // use extend() method for nuxt 6 // use extendWebpack() method for quasar 7 extendWebpack(config, { isServer, isClient }) { 8 config.module.rules.push({ 9 test: /\.vue$/, 10 loader: "vue-svg-inline-loader", 11 options: { /* ... */ } 12 }) 13 } 14 } 15};
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 svg-inline class="icon" focusable="false" role="presentation" tabindex="-1" xmlns="http://www.w3.org/2000/svg" viewBox="..."> 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 svg-inline svg-sprite class="icon" focusable="false" role="presentation" tabindex="-1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> 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 addAttributes: { 12 role: "presentation", 13 focusable: false, 14 tabindex: -1 15 }, 16 dataAttributes: [], 17 removeAttributes: ["alt", "src"], 18 transformImageAttributesToVueDirectives: true, 19 md5: true, 20 xhtml: false, 21 svgo: true, 22/* value true for svgo option is alias for: 23 svgo: { 24 plugins: [ 25 { 26 removeViewBox: false 27 } 28 ] 29 }, 30*/ 31 verbose: false 32}
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. -
dataAttributes:
Array of attributes which will be renamed to data-attributes. -
removeAttributes:
Array of attributes which will be removed. -
addAttributes:
Object of attributes which will be added. -
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. -
transformImageAttributesToVueDirectives:
Transforms all non-Vue image tag attributes to attributes set 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
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
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 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
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
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 More