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

v1.0.3

Published

(Not fully) A Vite plugin to bump version suffixes in source code.

Downloads

362

Readme

Vite Plugin Version Bumper

NPM Version License Downloads TypeScript

Automate your cache busting strategy. Updates version suffixes in your code (e.g., _v1_v2) physically. Designed to work flawlessly with Git Hooks and Vite.

InstallationUsageBest Practices

A Vite plugin and CLI tool that automatically bumps version numbers in your source code files. Perfect for cache busting, managing localStorage keys, or updating display versions.

🚀 Features

  • Standalone CLI: Fast "bump only" mode. Doesn't trigger a heavy Vite build.
  • Git Hooks Ready: Perfect for pre-commit hooks (Husky).
  • Automated Bumping: Increments version suffixes (e.g., _v1 -> _v2) automatically.
  • Fresh Start: Capable of resetting all versions back to _v1.
  • Physical Update: Updates the actual source code files.
  • Regex Powered: Flexible pattern matching via CLI flags.

📦 Installation

npm install -D vite-plugin-version-bumper
# or
yarn add -D vite-plugin-version-bumper

🕹 Usage

1. In your code

Write your variable with a version suffix:

// src/config.ts
export const CACHE_KEY = "user_settings_v1";

2. NPM Scripts (CLI)

The CLI tool (vite-bumper) is the recommended way to use this package. It modifies files without running a full build.

Note: The CLI does not read vite.config.ts. You must pass configuration via flags.

Update your package.json:

{
  "scripts": {
    "dev": "vite",
    "build": "vite build",

    // Default usage (Matches "_v1", "_v2" in src folder)
    "bump": "vite-bumper --bump",

    // Custom Pattern Usage (e.g. for "build_123")
    // Note: You must escape backslashes (\\d+) in JSON strings!
    "bump:custom": "vite-bumper --bump --pattern \"_build_(\\d+)\"",

    // Resets files back to 1
    "fresh": "vite-bumper --fresh"
  }
}

3. CLI Options Reference

| Flag | Description | Default | | :---------- | :-------------------------------------------------------------------- | :--------------------------- | | --bump | Increments found versions by 1. | false | | --fresh | Resets found versions to 1. | false | | --files | Glob pattern for files to scan. | "src/**/*.{ts,tsx,js,jsx}" | | --pattern | Regex string to match versions. Group 1 is prefix, Group 2 is number. | "(_v)(\d+)" |


⚙️ Configuration (Vite Plugin Mode)

Optional: Only required if you want the plugin to run inside vite build process automatically (not recommended if using Husky).

Add it to your vite.config.ts:

import { defineConfig } from "vite";
import versionBumper from "vite-plugin-version-bumper";

export default defineConfig({
  plugins: [
    versionBumper({
      files: "src/**/*.{ts,tsx,js,jsx}",
      pattern: /(_v)(\d+)/g,
    }),
  ],
});

💎 Best Practices: Husky & Git Hooks

The most professional way to use this plugin is to bump versions automatically before every commit. This ensures your production server never has to modify source code (avoiding dirty git state on CI/CD).

1. Install Husky

npm install -D husky
npx husky init

2. Configure Pre-commit Hook

Edit .husky/pre-commit:

#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

echo "🚀 Bumping version..."

# 1. Increment the version in source files
# (Ensure this script exists in your package.json)
npm run bump

# 2. Add the modified files back to the staging area
# (Crucial: otherwise the bump happens but isn't included in the commit)
git add .

# 3. (Optional) Run linting
# npx lint-staged

Now, every time you commit:

  1. Versions are bumped (_v1 -> _v2).
  2. The change is added to the commit.
  3. You push a clean, updated state to GitHub.
  4. Your VPS/Vercel pulls and builds without errors.

💡 Example Scenario: Cache Busting

You use localStorage to save user preferences. You need to invalidate old data after a deployment.

  1. Code: const STORAGE_KEY = "app_data_v1";
  2. Action: You commit your changes.
  3. Husky: Runs vite-bumper --bump.
  4. Result: Code becomes const STORAGE_KEY = "app_data_v2";.
  5. Effect: On production, the app looks for _v2. The old _v1 data is ignored, effectively resetting the state.

📄 License

MIT