vue-svg-loader-2: SVG as Vue Components

0.17.1 · active · verified Sun Apr 19

The `vue-svg-loader-2` package is a webpack loader designed to enable the direct import and usage of SVG files as Vue components within web applications. It serves as a actively maintained fork of the original `vue-svg-loader`, ensuring continued compatibility with modern build environments and addressing dependency updates. The current stable version is 0.17.1. While there isn't a strict, predictable release cadence, the project demonstrates ongoing activity through consistent dependency updates and minor fixes, indicating active maintenance. Its primary utility lies in simplifying the integration of SVGs into Vue applications, allowing developers to leverage Vue's component system for features like props, slots, and reactivity. It integrates seamlessly with popular webpack-based setups such as Vue CLI and Nuxt.js, and includes internal SVG optimization capabilities via SVGO.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to import local SVG files and use them directly as Vue components within a template after `vue-svg-loader-2` has been configured in the build process.

<template>
  <nav>
    <a href="https://github.com/vuejs/vue">
      <VueLogo />
      Vue
    </a>
    <a href="https://github.com/svg/svgo">
      <SVGOLogo />
      SVGO
    </a>
    <a href="https://github.com/webpack/webpack">
      <WebpackLogo />
      webpack
    </a>
  </nav>
</template>
<script>
import VueLogo from './public/vue.svg';
import SVGOLogo from './public/svgo.svg';
import WebpackLogo from './public/webpack.svg';

export default {
  name: 'Example',
  components: {
    VueLogo,
    SVGOLogo,
    WebpackLogo,
  },
};
</script>

view raw JSON →