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

xlian-version-plugin

v0.0.20

Published

xlian

Readme

xlian-version-plugin (Vite 插件)

简短说明

这是一个 Vite 插件,用于在构建开始时生成一个 public/v.json 文件,包含构建时间戳、版本号(从 .env 的 VITE_APP_VERSION 读取)和 git 短 hash(若可用)。

安装

  • 若作为本地插件,无需安装,直接从项目路径引入。
  • 若发布为 npm 包:
    • npm: npm i xlian-version-plugin
    • yarn: yarn add xlian-version-plugin
    • pnpm: pnpm add xlian-version-plugin

配置与引入(示例)

  • 通过本地文件引入(项目 ESM 环境):

    // filepath: /Users/mit-xl/code/version-plugin/README.md
    import xlianVersionPlugin from './index.js'; // 相对路径指向本插件的 index.js
    
    export default {
      // ...existing code...
      plugins: [
        xlianVersionPlugin(),
        // ...existing plugins...
      ],
      // ...existing code...
    }
  • 通过 npm 包引入(包名为 xlian-version-plugin):

    // filepath: /Users/mit-xl/code/version-plugin/README.md
    // CommonJS 环境(推荐,插件以 CommonJS 导出)
    const xlianVersionPlugin = require('xlian-version-plugin');
    
    module.exports = {
      // ...existing code...
      plugins: [ xlianVersionPlugin() ],
      // ...existing code...
    }

.env 配置

在项目根目录创建 .env.env.local,添加:

VITE_APP_VERSION=1.2.3

插件会读取该变量并写入到 public/v.jsonversion 字段。

输出文件示例(public/v.json)

{
  "timestamp": "2025-09-03 14-30-00",
  "version": "1.2.3",
  "hash": "a1b2c3d"
}

字段说明

  • timestamp: 本地化格式的构建时间字符串(zh-CN),用于显示或追踪构建时间。
  • version: 来自环境变量 VITE_APP_VERSION
  • hash: git 短 hash;若无法通过 git 获取,将为空字符串,插件会在控制台打印警告。

注意事项

  • 插件使用 dotenv 读取环境变量,请确保在运行时存在 .env(或通过其他方式设置 VITE_APP_VERSION)。
  • 获取 git hash 依赖于本地 git 可用性,CI 环境请确保安装并初始化 git 或提供其他机制。
  • 文件写入目标为项目的 public/v.json,若不存在目录会自动创建。
  • 该插件为 CommonJS 模块(使用 module.exports),在 ESM 项目中若需使用 import,可以通过构建工具的兼容配置或在项目 package.json 设置 "type": "module" 并使用默认导入互操作处理。

示例(完整的 vite.config.js 最小示例)

// filepath: /Users/mit-xl/code/version-plugin/README.md
import { defineConfig } from 'vite';
import xlianVersionPlugin from './index.js';

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

运行 package.json 中脚本(例如测试)

  • npm: npm test
  • yarn: yarn test
  • pnpm: pnpm test

许可证与贡献

可在此处补充许可证与贡献说明(如 MIT、PR 欢迎等)。