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

build-react-svg

v0.0.7

Published

自动化把 简单的svg icons(具体要求见下面的压缩规则)批量构建为react组件,并对svg进行内容压缩

Downloads

9

Readme

用途

自动化把 简单的svg icons(具体要求见下面的压缩规则)批量构建为react组件,并对svg进行内容压缩

const getCode = require('build-react-svg');
genCode(originDir, compsDir, demoFilePath, { defaultClass: 'lls-cc-svg-icon' });
  1. originsDir: 原始svg所在文件夹,里面的svg文件只能有一层, 不能存在 originsDir/xx/yy.svg, 只能是originsDir/yy.svg
  2. compsDir: 组件文件目录, react组件将会自己写入这个文件夹
  3. demoFilePath: 会生成一个 DemoComp, 包含所有的svg icons(样式可能需要自己写)
  4. options:
  • defaultClass, 默认是lls-svg-icon. 每个react svg 组件会加 className, 命名规则是 defaultClass + ' ' + 和fileName 的className
  • compTplStr, 生成 react component 的njk模板,默认为src/react.njk. 你可以根据需要进行微调。
  • demoTplStr, 生成 demo component 的njk模板。 用来展示所有生成的svg组件的,默认为src/demo.njk. 你可以根据需要进行微调。
  • svgo, svgo 实例,用来进行svg内容的压缩,具体参考 svgo 项目
  • force, 如果react component 已经存在,默认不覆盖,force 设为true, 强制覆盖

压缩规则

会对svg进行压缩,目前从 sketch 里export的简单icon,测试了有几十个,都可以work。要求原svg 主要的结构为

  <svg>
    <g>
      <some-tag />
      <path d="..."/>
    </g>
  </svg>

g tag里只有一个 path

压缩包括

  1. 去掉不必要的element, 一般情况只应该是 <svg><path /></svg> 这样的结构
  2. fillstroke 全部删掉,请使用css 进行颜色设置