
Research
NPM targeted by malware campaign mimicking familiar library names
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
vite-svg-loader
Advanced tools
vite-svg-loader is a Vite plugin that allows you to import SVG files as Vue components. This can be particularly useful for projects using Vue.js, as it enables you to easily manipulate and style SVGs using Vue's reactivity system.
Import SVG as Vue Component
This feature allows you to import an SVG file and use it as a Vue component. This makes it easy to include and manipulate SVGs within your Vue templates.
import MyIcon from './my-icon.svg';
export default {
components: {
MyIcon
},
template: '<MyIcon />'
};
Inline SVGs
By appending '?inline' to the import statement, you can import the SVG as an inline string. This can be useful for directly embedding SVGs into your HTML.
import MyIcon from './my-icon.svg?inline';
export default {
template: '<div v-html="MyIcon" />'
};
SVG Optimization
vite-svg-loader supports SVG optimization using SVGO. You can pass SVGO configuration options to optimize your SVGs during the build process.
import MyIcon from './my-icon.svg';
// vite.config.js
import { defineConfig } from 'vite';
import svgLoader from 'vite-svg-loader';
export default defineConfig({
plugins: [svgLoader({ svgoConfig: { /* SVGO options */ } })]
});
vite-plugin-svg-icons is another Vite plugin that allows you to use SVG icons in your project. It provides a similar functionality to vite-svg-loader but focuses more on managing a collection of SVG icons and generating an icon component library.
vite-plugin-vue-svg is a Vite plugin that also allows you to import SVG files as Vue components. It offers similar functionality to vite-svg-loader but may have different configuration options and defaults.
vite-plugin-svgr is a Vite plugin that transforms SVGs into React components. While it is designed for React rather than Vue, it provides similar functionality in terms of importing and using SVGs as components.
Vite plugin to load SVG files as Vue components, using SVGO for optimization.
<template>
<MyIcon />
</template>
<script setup>
import MyIcon from './my-icon.svg'
</script>
npm install vite-svg-loader --save-dev
vite.config.js
import svgLoader from 'vite-svg-loader'
export default defineConfig({
plugins: [vue(), svgLoader()]
})
SVGs can be imported as URLs using the ?url
suffix:
import iconUrl from './my-icon.svg?url'
// 'data:image/svg+xml...'
SVGs can be imported as strings using the ?raw
suffix:
import iconRaw from './my-icon.svg?raw'
// '<?xml version="1.0"?>...'
SVGs can be explicitly imported as Vue components using the ?component
suffix:
import IconComponent from './my-icon.svg?component'
// <IconComponent />
When no explicit params are provided SVGs will be imported as Vue components by default.
This can be changed using the defaultImport
config setting,
such that SVGs without params will be imported as URLs (or raw strings) instead.
vite.config.js
svgLoader({
defaultImport: 'url' // or 'raw'
})
vite.config.js
svgLoader({
svgoConfig: {
multipass: true
}
})
vite.config.js
svgLoader({
svgo: false
})
SVGO can be explicitly disabled for one file by adding the ?skipsvgo
suffix:
import IconWithoutOptimizer from './my-icon.svg?skipsvgo'
// <IconWithoutOptimizer />
If you use the loader in a Typescript project, you'll need to reference the type definitions inside vite-env.d.ts
:
/// <reference types="vite/client" />
/// <reference types="vite-svg-loader" />
Thanks to Nexxtmove for sponsoring the development of this project.
Your logo or name here? Sponsor this project.
FAQs
Vite plugin to load SVG files as Vue components
The npm package vite-svg-loader receives a total of 0 weekly downloads. As such, vite-svg-loader popularity was classified as not popular.
We found that vite-svg-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Socket uncovered npm malware campaign mimicking popular Node.js libraries and packages from other ecosystems; packages steal data and execute remote code.
Research
Socket's research uncovers three dangerous Go modules that contain obfuscated disk-wiping malware, threatening complete data loss.
Research
Socket uncovers malicious packages on PyPI using Gmail's SMTP protocol for command and control (C2) to exfiltrate data and execute commands.