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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@wj2025/css-webp-plugin

v1.0.2

Published

Webpack plugin that injects WebP background-image rules based on Modernizr style .webp/.no-webp classes.

Readme

@wj2025/css-webp-plugin

为 CSS 背景图片自动补充 WebP 版本规则(依赖 .webp/.no-webp 类进行能力检测)。可与 html-webp-pluginwebp-generate-plugin 搭配使用,实现端到端的 WebP 优化链路。

安装

npm install @wj2025/css-webp-plugin --save-dev
# or
yarn add -D @wj2025/css-webp-plugin

使用

const CssWebpPlugin = require('@wj2025/css-webp-plugin');

module.exports = {
  plugins: [
    new CssWebpPlugin({
      include: /\/img\//,
      exclude: null
    })
  ]
};

工作方式

  1. emit 阶段扫描输出的 CSS,收集背景图片规则;
  2. 为匹配到的规则生成 .webp .selector { background-image: url(xxx.webp) } 片段;
  3. 构建完成后,检查 WebP 文件是否真实存在,不存在则移除对应规则。

⚠️ 请确保在页面 <head> 中注入 WebP 检测脚本并给懒加载背景添加占位样式,示例:

<script>
  /* WebP 检测 - 内联执行以避免 FOUC */
  !function () {
    var img = new Image;
    img.onload = function () { (img.width > 0 && img.height > 0) && document.documentElement.classList.add("webp"); };
    img.onerror = function () { document.documentElement.classList.add("no-webp"); };
    img.src = "data:image/webp;base64,UklGRiQAAABXRUJQVlA4IBgAAAAwAQCdASoBAAEAAwA0JaQAA3AA/vuUAAA=";
  }();
</script>
<style>
  .bg-lazy.bg-lazy { background-image: none !important; }
</style>

这样 @wj2025/css-webp-plugin 生成的 .webp / .no-webp 规则才能即时生效。

配置项

| 选项 | 说明 | 默认值 | | --- | --- | --- | | include | 需要处理的图片路径正则 | /\/img\// | | exclude | 需排除的图片路径正则 | null |

License

MIT © wangjun