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

unplugin-images

v1.2.1

Published

自动扫描你的图片目录,生成可直接导入使用的常量映射文件(默认 `src/assets/r.ts`)。基于 [unplugin](https://github.com/unjs/unplugin),兼容 Vite、Rollup、Webpack、Rspack、esbuild、Farm、Nuxt、Astro 等生态。

Readme

unplugin-images

自动扫描你的图片目录,生成可直接导入使用的常量映射文件(默认 src/assets/r.ts)。基于 unplugin,兼容 Vite、Rollup、Webpack、Rspack、esbuild、Farm、Nuxt、Astro 等生态。

特性

  • 自动递归扫描图片目录(默认 src/assets/images
  • 按规则生成常量名,避免手写路径与拼写错误
  • 构建开始自动生成;开发环境可监听变更并自动再生成
  • 生成文件内容不变则跳过写入,避免不必要的重建
  • 在构建开始时生成图片常量文件,开发模式自动监听与增量生成;在构建结束时释放 watcher。

安装

# 推荐 pnpm
pnpm add -D unplugin-images
# 或
npm i -D unplugin-images
# 或
yarn add -D unplugin-images

快速开始(Vite)

// vite.config.ts
import Images from 'unplugin-images/vite'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [
    Images({
      // 可选:图片目录与输出文件(默认见下方“配置项”)
      // dir: 'src/assets/images',
      // dts: 'src/assets/r.ts',
    }),
  ],
})

在代码中使用(假设使用默认输出路径):

// 示例:在任意组件/模块中
import { R } from '@/assets/r' // 或根据你的路径别名/相对路径导入

// R.ICON_LOGO_PNG、R.BANNER_AT_2X_WEBP 等即为具体图片资源

生成文件(默认 src/assets/r.ts)的典型结构:

import ICON_LOGO_PNG from './images/icons/logo.png'
// ...

const R = {
  ICON_LOGO_PNG,
  // ...
}

export { R }

常量命名规则

  • 使用「目录名文件名后缀」的全大写下划线风格,例如:
  • 目录分隔符转换为下划线;- 转为 _@ 转为 _AT_
  • 后缀会追加为大写(如 _PNG_SVG

配置项 Options

interface Options {
  /** 图片目录(相对项目根目录或绝对路径) */
  dir?: string // 默认:'src/assets/images'
  /** 生成的常量文件路径(相对项目根目录或绝对路径) */
  dts?: string // 默认:'src/assets/r.ts'
  /** 是否在开发时监听变更自动再生成(默认:开发 true,生产 false) */
  watch?: boolean
  /** 项目根目录,用于解析相对路径(默认:process.cwd()) */
  root?: string
}

不同构建器的用法

// rollup.config.ts
import Images from 'unplugin-images/rollup'

export default {
  plugins: [
    Images({
      /* options */
    }),
  ],
}
// webpack.config.js
module.exports = {
  // ...
  plugins: [
    require('unplugin-images/webpack')({
      /* options */
    }),
  ],
}
// rspack.config.ts
import Images from 'unplugin-images/rspack'

export default {
  plugins: [
    Images({
      /* options */
    }),
  ],
}
// esbuild.config.ts
import { build } from 'esbuild'
import Images from 'unplugin-images/esbuild'

build({
  plugins: [Images()],
})
// farm.config.ts
import Images from 'unplugin-images/farm'

export default {
  plugins: [
    Images({
      /* options */
    }),
  ],
}
// nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    [
      'unplugin-images/nuxt',
      {
        /* options */
      },
    ],
  ],
})
// astro.config.mjs
import images from 'unplugin-images/astro'

export default {
  integrations: [
    images({
      /* options */
    }),
  ],
}

工作机制

  • 构建开始时会生成一次常量文件
  • watch: true(默认开发环境)时,监听图片文件与目录的新增/修改/删除并自动再生成
  • 若输出内容与上次完全一致,将跳过写入

许可协议

MIT