1.1.2 • Published 4 years ago

vue-sprited-svg-loader v1.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

vue-sprited-svg-loader

Build Status Coverage Status npm version

Simple svg sprite webpack loader for Vue to use .svg files as component. Based on svg-sprite-loader. With typescript support.

See Demo Example.

example image

Install

Requires svg-sprite-loader as first loader.

npm i -D vue-sprited-svg-loader svg-sprite-loader

Webpack Loader

module: {
    rules: [
        {
            test: /\.svg$/,
            use: [
                'vue-sprited-svg-loader',
                'svg-sprite-loader'
            ]
        }
    ]
}

Usage

Script

import IconFirst from './icons/icon-1.svg';
import IconSecond from './icons/icon-2.svg';

export default {
    components: {
        IconFirst,
        IconSecond
    }
};

Template

<div class="icons-example">
    <IconFirst class="first-icon"/>
    <IconSecond :style="{ fill: 'currentColor', color: 'red' }"/>
</div>

Usage inside Slot

By default component has slot named icon.

VueButton.vue

<button class="button">
    <slot name="icon"></slot>
    <slot></slot>
</button>

App.vue

<VueButton>
    <IconFirst />
    Press Me
</VueButton>

Props

width: string | number

Append width to style in pixels.

<MyIcon width="24" />

height: string | number

Append height to style in pixels.

<MyIcon height="24" />

size: string | number

Append both width and height to style in pixels.

<MyIcon size="24" />

Options

[
    {
        loader: 'vue-sprited-svg-loader',
        options: {
            customClass: 'icon',
            slotName: 'icon'
        }
    },
    'svg-sprite-loader'
]

customClass: string = ''

Add custom class to component

<svg class="customClass"> ... </svg>

slotName: string = 'icon'

Add custom slot name to component

<svg slot="slotName"> ... </svg>
1.1.2

4 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.1

5 years ago

0.1.1

5 years ago

0.0.1-f

5 years ago

0.0.1

5 years ago