Gathering detailed insights and metrics for svg-module-next
Gathering detailed insights and metrics for svg-module-next
npm install svg-module-next
Typescript
Module System
Node Version
NPM Version
42.6
Supply Chain
48.6
Quality
66.4
Maintenance
50
Vulnerability
98.6
License
JavaScript (73.76%)
Vue (26.24%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
290
Last Day
1
Last Week
2
Last Month
14
Last Year
52
MIT License
341 Stars
91 Commits
35 Forks
8 Watchers
6 Branches
41 Contributors
Updated on Jan 11, 2025
Latest Version
1.0.1
Package Id
svg-module-next@1.0.1
Unpacked Size
10.13 kB
Size
4.01 kB
File Count
5
NPM Version
8.19.2
Node Version
16.14.2
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-60%
2
Compared to previous week
Last Month
0%
14
Compared to previous month
Last Year
-36.6%
52
Compared to previous year
Super simple svg loading module for Nuxt.js
This package is for loading SVG's into Nuxt.js pages. It allows you to import .svg
files in multiple ways depending on the resource query you provide. Currently, this allows you to do the following:
file.svg
- normal import using file-loader
file.svg?data
- base64 data url import using url-loader
file.svg?inline
- inline import using vue-svg-loader
file.svg?raw
- raw html import using raw-loader
file.svg?sprite
- SVG sprite using svg-sprite-loader
1npm install --save-dev svg-module-next
1// nuxt.config.js 2export default { 3 buildModules: ["svg-module-next"], 4};
And that's it! You don't have to install anything else, you're ready to go.
1// nuxt.config.js 2export default { 3 svg: { 4 vueSvgLoader: { 5 // vue-svg-loader options 6 }, 7 svgSpriteLoader: { 8 // svg-sprite-loader options 9 }, 10 fileLoader: { 11 // file-loader options 12 } 13 } 14};
The usage examples are documented as:
1<!-- Nuxt.js code -->
1<!-- Outputted html -->
file-loader
1<template> 2 <img src="~assets/nuxt.svg" /> 3</template>
1<img src="/_nuxt/9405b9978eb50f73b53ac1326b93f211.svg" />
url-loader
1<template> 2 <img src="~assets/nuxt.svg?data" /> 3</template>
1<img src="data:image/svg+xml;base64,P...2h913j1g18h98hr" />
vue-svg-loader
1<template> 2 <NuxtLogo /> 3</template> 4 5<script> 6 import NuxtLogo from "~/assets/nuxt.svg?inline"; 7 8 export default { 9 components: { NuxtLogo }, 10 }; 11</script>
1<svg xmlns="http://www.w3.org/2000/svg"><path></path></svg>
raw-loader
Load the raw SVG data as HTML using raw-loader
:
1<template> 2 <div v-html="rawNuxtLogo" /> 3</template> 4 5<script> 6 import rawNuxtLogo from "~/assets/nuxt.svg?raw"; 7 8 export default { 9 data() { 10 return { rawNuxtLogo }; 11 }, 12 }; 13</script>
1<div> 2 <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 298"> 3 <g fill-rule="nonzero" fill="none"><path></path></g> 4 </svg> 5</div>
svg-sprite-loader
1<template> 2 <svg :viewBox="spriteNuxtLogo.viewBox"> 3 <use :xlink:href="'#' + spriteNuxtLogo.id"></use> 4 </svg> 5</template> 6 7<script> 8 import spriteNuxtLogo from "~/assets/nuxt.svg?sprite"; 9 10 export default { 11 data() { 12 return { spriteNuxtLogo }; 13 }, 14 }; 15</script>
1<svg viewBox="0 0 400 298"> 2 <use xlink:href="#nuxt--sprite"></use> 3</svg>
To dynamically import an SVG, you can use the inline require()
syntax.
1<template> 2 <div v-html="require(`../assets/${name}.svg?raw`)" /> 3</template> 4 5<script> 6 export default { 7 props: { 8 name: { type: String, default: "image" }, 9 }, 10 }; 11</script>
This example uses
raw-loader
.
To render an SVG without wrapper element and the use of v-html
, a combination of dynamic components and ?inline
can be used. See #72 for context.
1<template> 2 <component :is="require(`../assets/${name}.svg?inline`)" /> 3</template> 4 5<script> 6 export default { 7 props: { 8 name: { type: String, default: "image" }, 9 }, 10 }; 11</script>
This example uses
vue-svg-loader
.
In order for this module to work correctly, the default .svg
Nuxt.js webpack rule gets replaced with this handler.
The only difference between this and the handler is that there is no limit
for when file-loader
replaces url-loader
.
So when using the ?data
query, it will always use url-loader
regardless of file size, and when not using either resource query, it will always use file-loader
).
As this loader attempts to abstract webpack configuration from the process and make it easier to use multiple svg loaders, any contributions that add more svg loader methods to the configuration will be accepted wholeheartedly!
Copyright (c) Sam Holmes
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 7/26 approved changesets -- score normalized to 2
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
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
77 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-02-10
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