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

remove-unused-assets

v1.0.5

Published

一个用于分析未使用静态资源的工具

Downloads

5

Readme

remove-unused-assets

NPM Version License: MIT

说明

这是一个用于分析项目中未使用静态资源的工具,会分析出哪些静态资源没有被引用,并生成一个列表。支持常规 Web 项目和微信小程序项目。

特性

  • 支持分析静态资源引用
  • 支持动态路径分析(如模板字符串和变量拼接)
  • 支持微信小程序项目
  • 生成详细的分析报告

动态路径支持

工具现在可以识别以下类型的动态路径:

  1. 模板字符串:`path/to/img/pic_${index}.png`
  2. 字符串拼接:'path/to/img/pic_' + index + '.png'

当检测到动态路径时,工具会分析路径的基础目录(如 path/to/img/),并将该目录下的所有匹配文件标记为"可能被使用",以避免误报。

安装

全局安装

npm install -g remove-unused-assets
# 或者使用 yarn
yarn global add remove-unused-assets
# 或者使用 pnpm
pnpm add -g remove-unused-assets

项目内安装

npm install --save-dev remove-unused-assets
# 或者使用 yarn
yarn add --dev remove-unused-assets
# 或者使用 pnpm
pnpm add -D remove-unused-assets

使用方法

命令行使用

全局安装后,可以直接在任何项目目录下使用:

remove-unused-assets --dir ./src --pattern "**/*.{png,jpg,jpeg,gif,svg,ico}"

简写命令

remove-unused-assets -d ./src -p "**/*.{png,jpg}"

微信小程序项目

对于微信小程序项目,可以使用 -w--wechat 参数启用微信小程序模式:

remove-unused-assets -d ./miniprogram -p "**/*.{png,jpg,jpeg,gif,svg}" -w

微信小程序模式下,工具会额外检查 WXML 中的图片引用(如 <image src="..."> 标签)和 WXSS 中的背景图片引用。

在项目中使用

在 package.json 中添加脚本:

{
  "scripts": {
    "find-unused": "remove-unused-assets --dir ./src",
    "find-unused-wxapp": "remove-unused-assets --dir ./miniprogram --wechat"
  }
}

然后运行:

npm run find-unused
# 或者微信小程序项目
npm run find-unused-wxapp

参数说明

  • -d, --dir <directory>: 指定要分析的目录,默认为当前目录 (.)
  • -p, --pattern <pattern>: 静态资源文件匹配模式,默认为 **/*.{png,jpg,jpeg,gif,svg,ico}
  • -o, --output <file>: 输出结果文件名,默认为 unused-assets.txt
  • -w, --wechat: 启用微信小程序模式,会检查 WXML 和 WXSS 中的资源引用
  • -v, --version: 显示版本号
  • -h, --help: 显示帮助信息

支持的文件类型

  • 源代码文件:js, jsx, ts, tsx, vue, html, css, scss, sass, less
  • 微信小程序文件:wxml, wxss, json
  • 静态资源文件:png, jpg, jpeg, gif, svg, ico 等(可通过 pattern 参数自定义)

示例

查看 example 目录获取使用示例。

贡献指南

  1. Fork 本仓库
  2. 创建你的特性分支 (git checkout -b feature/amazing-feature)
  3. 提交你的更改 (git commit -m 'Add some amazing feature')
  4. 推送到分支 (git push origin feature/amazing-feature)
  5. 开启一个 Pull Request

开源协议

本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。