Skip to content

将SVG加载为Vue 组件!!! import svg as vue component with webpack!!!

License

Notifications You must be signed in to change notification settings

zyascend/vue-svg-sfc-loader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

vue-svg-sfc-loader

import SVG as Vue Component with webpack !!!

将SVG文件加载为Vue组件

Installation

npm i vue-svg-sfc-loader -D
yarn add vue-svg-sfc-loader -D

Configuration

use vue-svg-sfc-loader as the last loader of the SVG laoders

vue-svg-sfc-loader 作为处理SVG的最后一个loader

Webpack

module.exports = {
  module: {
    rules: [
      {
        test: /\.svg$/,
        use: [
          {
            loader: 'vue-svg-sfc-loader',
            options: {
              className: 'myclass'
            }
          },
        ],
      },
    ],
  },
};

Vue CLI

module.exports = {
  chainWebpack: config => {
    const svgRule = config.module.rule('svg')
    svgRule.uses.clear()
    svgRule
      .use('vue-svg-sfc-loader')
      .loader('vue-svg-sfc-loader')
      .options({
        className: 'myclass'
      })
      .end()
  },
};

options

className

type: string

default value: class

add custom class props to <svg>

the render result:

<svg class='myclass' ...>
  ...
</svg>

About

将SVG加载为Vue 组件!!! import svg as vue component with webpack!!!

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published