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-version-injector

v2.1.1

Published

A universal plugin to inject version and build time into HTML (supports Webpack, Vite, Rollup)

Readme

🚀 unplugin-version-injector - 自动注入版本号与构建时间

🇬🇧 English README | 🇨🇳 中文文档


📌 插件简介

unplugin-version-injector 是一个轻量级插件,可在构建时自动向所有 HTML 文件注入 版本号构建时间戳项目名。支持 Webpack 4/5、Vite 和 Rollup,适用于 SPA / MPA 项目


✨ 功能亮点

✅ 自动注入 <meta name="version"><meta name="project"> 到 HTML <head>
✅ 自动注入 <script>,控制台输出 项目名版本号构建时间
✅ 支持 Webpack 4 / 5、Vite、Rollup
✅ 完美兼容多页面应用(MPA)
✅ 支持自定义版本号、项目名、时间格式,默认读取 package.json
✅ 控制台输出支持自动适配深/浅主题配色


📦 安装

# 使用 yarn
yarn add -D unplugin-version-injector

# 使用 npm
npm install -D unplugin-version-injector

🚀 使用方法

📌 Vite

vite.config.ts 中配置:

import versionInjector from 'unplugin-version-injector/vite';

export default {
  plugins: [versionInjector()],
};

📌 Webpack 4/5

webpack.config.js 中配置:

const versionInjector = require('unplugin-version-injector/webpack');

module.exports = {
  plugins: [
    versionInjector({
      version: '1.2.3', // 可选,自定义版本号
      name: 'MyApp'     // 可选,自定义项目名
    }),
  ],
};

📌 Rollup

rollup.config.js 中配置:

import versionInjector from 'unplugin-version-injector/rollup';

export default {
  plugins: [versionInjector()],
};

🧪 示例输出

构建后的 HTML 文件中将自动注入:

<head>
  <meta name="version" content="1.2.3">
  <meta name="project" content="MyApp">
</head>
<body>
  ...
  <script data-injected="unplugin-version-injector">
    console.log(...);
  </script>
</body>

控制台输出(根据主题自适应配色):

🟦 Project: MyApp
🟢 Version: 1.2.3
🟡 Build Time: 2024-06-04T12:00:00.000Z

🔧 配置项说明

| 选项 | 类型 | 说明 | 默认值 | |--------------|-----------|----------------------------------|---------------------| | version | string | 自定义版本号 | 自动读取 package.json | | name | string | 自定义项目名 | 自动读取 package.json | | log | boolean | 是否输出控制台日志 | true | | formatDate | Date => string | 自定义时间格式函数 | ISO 格式 |


🎨 控制台配色自动适配说明

  • 插件自动判断浏览器是否为暗色模式(window.matchMedia('(prefers-color-scheme: dark'));
  • 深色模式下将使用亮色字体以确保可读性;
  • 你也可以重写 <script> 注入逻辑以自定义样式。

📜 开源许可

MIT License © 2024 Nian YI


🔥 unplugin-version-injector —— 最轻巧的版本信息注入解决方案!