@svgv/webpack

Webpack loader to transform SVGs into Vue components.
1,578 4
Install
npm install @svgv/webpack
Latest Version:0.1.0
Vue:3
License:MIT
Last Updated:Mar 1, 2024
Links: GitHub  ·  npm
Maintainer: marella

@svgv/webpack tests Coverage Status

Webpack loader to transform SVGs into Vue components.

Installation

npm install @svgv/webpack --save-dev

Usage

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.svg$/,
        use: ['vue-loader', '@svgv/webpack'],
      },
    ],
  },
};
vue.config.js
module.exports = {
  chainWebpack: (config) => {
    const svgRule = config.module.rule('svg');
    svgRule.uses.clear();
    svgRule
      .use('vue-loader')
      .loader('vue-loader')
      .end()
      .use('@svgv/webpack')
      .loader('@svgv/webpack')
      .end();
  },
};

App.vue

<template>
  <div>
    <Star />
  </div>
</template>

<script>
import Star from './star.svg';

export default {
  components: {
    Star,
  },
};
</script>

Using with url-loader or file-loader

Note: This is an experimental feature.

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.svg$/,
        use: ['vue-loader', '@svgv/webpack', 'url-loader'],
      },
    ],
  },
};
vue.config.js
module.exports = {
  chainWebpack: (config) => {
    const svgRule = config.module.rule('svg');
    svgRule.uses.clear();
    svgRule
      .use('vue-loader')
      .loader('vue-loader')
      .end()
      .use('@svgv/webpack')
      .loader('@svgv/webpack')
      .end()
      .use('url-loader')
      .loader('url-loader')
      .end();
  },
};

App.vue

<template>
  <div>
    <img :src="https://raw.githubusercontent.com/marella/svgv/HEAD/Star" />
    <Star />
  </div>
</template>

<script>
import Star from './star.svg';

export default {
  components: {
    Star,
  },
  data() {
    return {
      Star,
    };
  },
};
</script>

Examples

See examples.

License

MIT

Related Packages

vue-svg-loader

Use SVG files as Vue Components

3,476,564 645
@nuxtjs/markdownit-loader

Webpack loader to translate markdown to HTML using markdownit.

325,518 11
vue-svg-icon-loader

Turn SVG files into Vuejs Icon Components

77,615 23
svg-vue3-loader

Use SVG files as Vue Components

33,575 0
svg-vue-loader

Use SVG files as Vue Components

2,606 0

Version History

Version Released Vue License
0.1.0 ^3.1.1 MIT