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

kiss-icon-vue-plugin

v1.0.3

Published

webpack plugin for svg

Downloads

2

Readme

kiss-icon-vue-plugin


这是个webpack的插件,主要是为了线上svg图标的项目服务,将工程里(暂时只处理vue)用到的图标生成对应的css和字体文件。

优点是不需要引用没用到的图标,文件体积减小;也不需要再复制各种图标到本地工程目录。只需要请求远程服务器即可。

核心思想是,新加一个loader,解析出vue文件里需要的svg图标名称,将它们下载到本地目录,再用@vusion/webfonts-generator生成字体和css文件,开发时会在js中引用这个css,打包时会一起写入css文件。


使用说明

# npm
npm i -D kiss-icon-vue-plugin

# yarn
yarn add kiss-icon-vue-plugin --dev

vue-cli创建的工程中使用方法

vue.config.js中配置pluginloader, 如果使用TypeScript请在loader参数中添加useTs字段并将其值设置为true,具体参考如下配置。
vue.config.js

const path = require('path');
const KissIconPlugin = require('kiss-icon-vue-plugin');

module.exports = {
    chainWebpack: config => {
        KissIconPlugin.Util.chainWebpack(config, {
            remotePath: 'https://example/',
            downloadable: ['adjust'],
            useTs: true, //  使用TypeScript
        })
    },
    configureWebpack: {
        plugins: [
            new KissIconPlugin.IconPlugin()
        ]
    }
}

main.js中导入全局组件
vue2:

import Vue from 'vue'
import KissUIcon from 'kiss-icon-vue-plugin/src/index.vue'
Vue.component('UIcon', KissUIcon);

vu3:

import { createApp } from 'vue'
import KissUIcon from 'kiss-icon-vue-plugin/src/index.vue'
createApp(App).component(
    'UIcon',
    KissUIcon
).mount('#app')

在组件中使用:

<UIcon uinoSvg="affiliatetheme"></UIcon>
<UIcon :uinoSvg="true? 'affiliatetheme' : 'moon'"></UIcon>
<UIcon :uinoSvg="icon"></UIcon>

如果使用:或者v-bind:语法糖请在vue.config.js手动注入所需的svg。


使用自己的组件:

如果想使用自己的icon组件的话,请设置class名为你自己配置的。在配置loader传入的参数中设置prefix为自己的命名(默认为uk),并且将labelName设置为你自己的组件名(默认为UIcon),最后设置attributeName(默认为uinoSvg)为你自己图标组件的属性名。

例:
example.vue

<template>
  <i
      :class="prefix"
      :class="prefix + '_' + attributeName">
  </i>
</template>

<script>
export default {
  name: 'example',
  data(){
    return {
      prefix: 'example',
    }
  },
  props: {
    attributeName: String,
  },
}
</script>

App.vue

<template>
    <Icon uinoSvg="address_book"></Icon>
    <Icon uinoSvg="ad"></Icon>
</template>

<script>
  import Icon from './components/example.vue';
  export default{
    name: 'App',
    components: {
      "Icon": Icon
    }
  }
</script>

配置项

remotePath

required
Type: string
远程资源服务器的地址,比如http://localhost:4001/ 我们在使用时只需要填入图标名即可,插件会自动填入后缀.svg,目前仅支持svg格式。

downloadable

Type: Array.<string>
额外的图标名称,即这种使用变量的情况,需要把真实的图标名称在这里配置下。

prefix:

Type: String
Default: uk
生成的css的前缀名与图标字体的类名

labelName:

Type: String
Default: UIcon
组件的tag

attributeName:

Type: String
Default: uinoSvg
给组件传入的属性名称

useTs:

Type: Boolean
Default: false
是否使用了TypeScript

headers:

Type: Object 请求头部信息。

注意:

如果遇到 cannot read property 'parsecomponent' of undefined这个错误,请确定工程中vuevue-template-compiler版本一致,如果继续报错请检查vue-loader版本是否>=16