npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vue-svg-iconx

v1.0.1

Published

Svg icon component based on vue

Downloads

2

Readme

vue-svg-iconx

Svg icon component based on vue

Install

npm i vue-svg-iconx
npm i svg-sprite-loader svgo svgo-loader -D

How to use

webpack config (use vue-cli 3)

You need a directory to store your SVG icon files. For example: src/assets/icon

You may need to give your icon a prefix. For example: icon-

You can change them to whatever value you want

vue.config.js

const path = require("path");

function resolve(dir) {
  return path.join(__dirname, dir);
}

module.exports = {
  chainWebpack(config) {
    config.module
      .rule("svg")
      .exclude.add(resolve("src/assets/icon")) // This is your svg icon directory.
      .end();

    config.module
      .rule("svg-icon")
      .test(/\.(svg)(\?.*)?$/)
      .include.add(resolve("src/assets/icon")) // This is your svg icon directory.
      .end()
      .use("svg-sprite-loader")
      .loader("svg-sprite-loader")
      .options({
        symbolId: "icon-[name]" // This is your icon prefix
      })
      .end()
      .use("svgo-loader")
      .loader("svgo-loader")
      .options({
        externalConfig: resolve("svgo.yml") // svgo config file
      })
      .end();
  }
};

svgo.yml

plugins:
  - cleanupAttrs: true
  - removeDoctype: true
  - removeComments: true
  - removeTitle: true
  - removeDesc: true

OK, Let`s start!

import iconx from "vue-svg-iconx";

// Import all svg, svg-sprite-loader and svgo-loader will automatically handle them for you
const requireAll = requireContext => requireContext.keys().map(requireContext);
requireAll(require.context("@/assets/icon", false, /\.svg$/));

Vue.use(iconx);
<template>
  <div>
    <iconx name="loading"></iconx>

    Support rotate

    <iconx rotate name="loading" color="#000" size="100px"></iconx>
  </div>
</template>

Component props

  • name <String>

    required: Yes.

    The value of name is equal to the file name of the svg you want to display.

  • color <String>

    required: No

  • size <String, Array>

    required: No

    example:

    <icon name="loading" size="50px"></icon>
    
    ->
    
    <svg style="font-size: 50px">...</svg>
    
    --------------------------------------------------------
    
    <icon name="loading" :size="['50px']"></icon>
    
    ->
    
    <svg style="width: 50px; height: 50px">...</svg>
    
    --------------------------------------------------------
    
    <icon name="loading" :size="['50px', '60px']"></icon>
    
    ->
    
    <svg style="width: 50px; height: 60px">...</svg>
  • rotate <Boolean>

    required: No

Customizable

Support for custom component names and global icon prefixes when registering.

import iconx from "vue-svg-iconx";

Vue.use(iconx, {
  componentName: "icon" // default: iconx
  prefix: 'iconx-'      // default: icon-
});