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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@svg-extract-color/svg-extract-color-loader

v1.0.3-beta

Published

A Webpack Loader to extract svg color

Downloads

12

Readme

svg-extract-color-loader

为什么需要 svg-extract-color

当我们使用了 SVG Sprite 时,我们希望能够通过use标签修改 SVG 的颜色。有些 SVG 可以通过为use标签传入color属性修改 SVG 颜色;有些 SVG 需要先将内部的所有fill与stroke属性删除,才能通过为use标签传入color属性修改 SVG 颜色;有些 SVG 即使将内部的所有fill与stroke属性删除,也无法通过为use标签传入color属性修改 SVG 颜色;

上述情况示例

他是如何工作的

本loader需要与svg-sprite-loader搭配使用

编译阶段会将 SVG 中的所有颜色属性值会由原颜色替换为 CSS 变量调用形式 var(--color, 原颜色属性值) 。在运行时,我们在需要修改颜色的use标签中传入 CSS 变量即可修改颜色。

<!-- 单独使用 svg-sprite-loader -->
<svg>
  <use xlink:href="#icon-plus" style="color: red" />
</svg>
<!-- 使用 svg-sprite-loader & svg-extract-color-loader -->
<svg>
  <use xlink:href="#icon-plus" style="--color: red" />
</svg>

安装

npm install @svg-extract-color/svg-extract-color-loader -D
# or
yarn add @svg-extract-color/svg-extract-color-loader -D
# or
pnpm install @svg-extract-color/svg-extract-color-loader -D

如何使用

本loader需要与svg-sprite-loader搭配使用

且目前只支持修改单色 SVG

{
  test: /\.svg$/,
  use: [
    'svg-sprite-loader',
    '@svg-extract-color/svg-extract-color-loader',
  ],
}

cssVariableName

cssVariableName 用于设置 SVG 中使用的 CSS 变量名,这会影响use标签中传入的 CSS 变量名,默认值为: --color

options: {
  cssVariableName: '--svg-color'
}
<svg>
  <use xlink:href="#icon-complex" style="--svg-color: red">
</svg>

示例

请参阅示例