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

@yuo/vite-plugin-svg-icons

v1.0.0

Published

@yuo/vite依赖插件,sprite技术

Downloads

2

Readme

@yuo/vite-plugin-svg-icons

原理说明

@yuo/vite打包时, 会把指定目录下所有svg统一打包形成精灵图, 并挂载到dom上隐藏起来。

<svg
    id="__svg__icons__dom__"
    xmlns="http://www.w3.org/2000/svg"
    xmlns:link="http://www.w3.org/1999/xlink"
    style="position: absolute; width: 0px; height: 0px;"
>
    <symbol viewBox="0 0 1025 1024" id="ic-xx"></symbol>
    <symbol viewBox="0 0 1025 1024" id="ic-xx"></symbol>
</svg>

@yuo/vite默认仅允许 import 图片的路径,拿不到svg本身的文本内容。但是svg支持精灵图技术,本插件 正是依赖这一项技术。可以在Vue单文件组件中使用,<use />引用dom上的symbol元素。

<use :xlink:href="`#ic-${name}`" />

下载安装

npm i @yuo/vite-plugin-svg-icons -D

vite.config.ts配置

// vite.config.ts
import { defineConfig } from '@yuo/vite';
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';

export default defineConfig({
    // ...
    plugins: [
        // vue(),

        // https://github.com/vbenjs/vite-plugin-svg-icons
        createSvgIconsPlugin({

            // 指定某个目录为静态svg icon存放的路径
            iconDirs: [resolve(__dirname, 'src/assets/icons')],

            // 生成的<symbol>中id属性格式,注意未划分子目录,id会自动去掉 -[dir], 为 ic-[name]
            symbolId: 'ic-[dir]-[name]',
        }),     
    ]
});

使用方式

第一步选择你需要使用的svg图片,压缩一下!

推荐一个国内访问的好用的svg离线压图网站,不必担心资源外露

第二步将压缩后的图片修改为统一大小,删去无用的class/style/id等属性值

阿里巴巴图标库中很多东西要作为字体,写了许多冗余兼容和待拓展的字段,均需删去,压缩体积。

第三步使用它!

<!-- xx.vue -->
<template>
    <use :xlink:href="symbolId" style="..." />
</template>