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

vite-plugin-app-version

v0.2.0

Published

Vite plugin to generate an app version file (version.json) and optional virtual module with git/tag/build metadata.

Readme

vite-plugin-app-version

npm version
license

Vite plugin to generate an app version file (version.json) and an optional virtual module with git/tag/build metadata.
Useful for displaying build info in your app, cache busting, or runtime version checking.


✨ Features

  • Generates a version.json file at build time
  • Serves version.json in dev mode with Cache-Control: no-store + ETag
  • Provides a virtual module (virtual:app-version) you can import in-app
  • Dynamic TypeScript interface for virtual module, matching publicFields and extraFields
  • Exported async function checkVersion() to detect runtime version updates
  • Exported subscription function onCheck(cb) to listen for results of checkVersion()
  • Includes pkgVersion, git tag/commit, buildTime, and current mode
  • Customizable public fields and extra custom fields
  • No external runtime dependency

📦 Installation

npm install vite-plugin-app-version --save-dev
# or
yarn add -D vite-plugin-app-version
# or
pnpm add -D vite-plugin-app-version

🚀 Usage

Add the plugin in your vite.config.ts:

import {defineConfig} from "vite";
import {generateVersion} from "vite-plugin-app-version";

export default defineConfig({
    plugins: [
        generateVersion({
            filename: "version.json", // default
            publicFields: ["pkgVersion", "version", "commitShort", "buildTime"], // default fields
            exposeVirtual: true, // enables import from 'virtual:app-version'
            extraFields: {       // 👈 you can add custom fields too
                env: process.env.NODE_ENV,
                apiUrl: "https://api.example.com",
                release: 42
            }
        })
    ]
});

In your app (frontend code)

import version, {checkVersion, onCheck} from "virtual:app-version";

console.log("App version info:", version);

// Subscribe to every check
onCheck(({updated, latest}) => {
    if (updated) {
        console.log("🔄 New version available:", latest?.version);
    } else {
        console.log("✅ Still up to date");
    }
});

// Run a check manually
setInterval(() => {
    checkVersion(); // triggers onCheck listeners
}, 30000);
  • The TypeScript interface AppVersion automatically includes the fields from publicFields and extraFields.
  • onCheck returns an unsubscribe function if you want to remove the listener.

From version.json

  • Dev mode: available at http://localhost:5173/version.json
  • Build mode: emitted to your /dist or /public

Example content:

{
  "pkgVersion": "0.1.0",
  "version": "v1.2.3",
  "commitShort": "abc1234",
  "buildTime": "2025-09-09T14:00:00.000Z",
  "env": "development",
  "apiUrl": "https://api.example.com",
  "release": 42
}

⚙️ Options

| Option | Type | Default | Description | |-----------------|------------------------|------------------------------------------------------|-----------------------------------------------------| | filename | string | "version.json" | Output file name | | publicFields | (keyof FullInfo)[] | ["pkgVersion","version","commitShort","buildTime"] | Fields to expose in JSON and virtual module | | exposeVirtual | boolean | true | Enable the virtual module import (virtual:app-version) | | extraFields | Record<string, any> | {} | Extra custom fields to merge into JSON and typings |

FullInfo fields

type FullInfo = {
    version: string;        // git tag / commit / fallback: timestamp
    commitShort: string;    // short git commit hash
    pkgVersion: string;     // package.json version
    buildTime: string;      // ISO timestamp
    mode: string;           // vite mode (development | production)
};

🛠️ Example: Only version + buildTime

generateVersion({
    publicFields: ["version", "buildTime"],
    exposeVirtual: true
});
import info, {checkVersion, onCheck} from "virtual:app-version";

console.log(info.buildTime); // TS autocomplete works

onCheck((res) => {
    if (res.updated) {
        console.log("New version available:", res.latest?.version);
    }
});

// Runtime version check
checkVersion();

🤝 Contributing

PRs and issues welcome!
👉 Open an issue


📄 License

MIT © dev-zarghami