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

version-watcher

v1.0.8

Published

轻量级前端版本监听工具,用于检测站点版本变化,并在同源标签页之间共享版本状态与刷新动作。

Downloads

22

Readme

Version Watcher

轻量级前端版本监听工具,用于检测站点版本变化,并在同源标签页之间共享版本状态与刷新动作。

核心能力

  • 浏览器端自动轮询版本文件,并在检测到新版本时弹出更新提示
  • 同一 origin 下优先复用单个 SharedWorker,不为每个标签页重复创建独立轮询 worker
  • 自动降级到 Worker,再降级到主线程 fallback,保证不支持 SharedWorker 的环境也能工作
  • 支持同源标签页之间的版本同步与刷新广播
  • 支持 webpack、Vite、Vue CLI 的构建插件,自动生成 version.json
  • 提供本地联调 example 与发布后 smoke 验证工程

安装

npm install version-watcher

快速开始

Vue 插件方式

import { createApp } from 'vue'
import VersionWatcher from 'version-watcher'
import App from './App.vue'

const app = createApp(App)

app.use(VersionWatcher, {
  endpoint: '/dist/version.json',
  interval: 5 * 60 * 1000,
  content: '发现新版本,请刷新当前页面。',
  refreshSameOrigin: true,
})

app.mount('#app')

说明:app.use(VersionWatcher, options) 会安装插件,但不会把实例暴露给外层。如果你需要手动调用 checkNow()、读取运行模式或在页面销毁时主动清理资源,请显式创建 VersionWatcherInstance

手动实例方式

import { VersionWatcherInstance } from 'version-watcher'

const watcher = new VersionWatcherInstance({
  endpoint: '/dist/version.json',
  polling: false,
  checkNowThrottleTime: 5000,
})

watcher.checkNow()
console.log(watcher.getMode())
console.log(watcher.getTabCount())

window.addEventListener('beforeunload', () => {
  watcher.destroy()
})

构建插件

webpack / Vue CLI

const VersionWatcherPlugin = require('version-watcher/plugin')

module.exports = {
  configureWebpack: {
    plugins: [new VersionWatcherPlugin()],
  },
}

Vite

import { defineConfig } from 'vite'
import VersionWatcherPlugin from 'version-watcher/plugin/vite'

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

常用验证命令

npm test
npm run build
npm run verify:node
npm run smoke:pack
  • npm test:运行仓库内的回归测试
  • npm run build:构建发布产物
  • npm run verify:node:校验插件入口在 Node 环境下可正确加载
  • npm run smoke:pack:使用 npm pack 产物验证 Vite、webpack 5、Vue CLI 5 三条真实消费链路

文档导航

License

MIT