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

@cdf-rd-fe/publish-notification-plugin

v0.1.5

Published

Web version update notice toolkit (Runtime API + Vite version.json helper)

Readme

@cdf-rd-fe/publish-notification-plugin

业务背景:用户长时间停留在旧页面、后台发版后仍继续操作,导致功能异常或数据不一致。

业务能力: 1、运行时对比「当前页版本」与「线上最新版本」。用户无需改业务逻辑,接入后即可感知发版。

​ 2、仅在窗口在前台、Tab 可见、且(微前端下)当前激活应用时检查。后台 Tab、未打开的子应用不打扰用户。

​ 3、静态脚本/样式加载失败时也会触发检查,便于发现「发版后旧 chunk 已失效」这类情况。

Web 版本更新提醒工具包:Runtime API + 薄构建辅助(只生成 version.json,不注入 HTML / 脚本)。本版以 Vite 为主。

安装

pnpm add @cdf-rd-fe/publish-notification-plugin

单体应用(Vite 双零配置)

// vite.config.ts
import { defineConfig } from 'vite'
import { vitePluginVersion } from '@cdf-rd-fe/publish-notification-plugin/vite'

export default defineConfig({
  plugins: [vitePluginVersion()],
})
// main.ts
import { createUpdateNotice } from '@cdf-rd-fe/publish-notification-plugin'

createUpdateNotice()

微前端(qiankun)

每个子应用各自接入 vitePluginVersion() + createUpdateNotice;Host 同步 setActiveApp

// vite.config.ts
import { defineConfig } from 'vite'
import { vitePluginVersion } from '@cdf-rd-fe/publish-notification-plugin/vite'

export default defineConfig({
  plugins: [vitePluginVersion()],
})
// 主应用: host/main.ts
import { createUpdateNotice, getUpdateNotice } from '@cdf-rd-fe/publish-notification-plugin'

createUpdateNotice({
  microApp: { enabled: true, appId: 'host' },
  // 主应用纯壳(可选):disableNotification: true,
})

registerMicroApps(apps, {
  beforeMount: [
    (app) => {
      // 激活子应用(插件只检查激活子应用是否有版本,不检查其他子应用)
      getUpdateNotice()?.setActiveApp(app.name)
      return Promise.resolve()
    },
  ],
})
// 子应用:order/main.ts
createUpdateNotice({
  microApp: { enabled: true, appId: 'order-center' },
})

事后切换语言 / 主题

import { getUpdateNotice } from '@cdf-rd-fe/publish-notification-plugin'

// 切换语言
getUpdateNotice()?.setLocale('en_US')
// 切换主题 (Antd 4.x + 5.x +6.x 主题会自动适配,不需要额外配置,可以不用写下面这行)
getUpdateNotice()?.setTheme('dark')

UpdateNoticeOptions

createUpdateNotice(options?) 的运行时配置。

| 字段 | 类型 | 默认 | 说明 | | --------------------- | ----------------------- | ------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | versionBase | string | 自动推导 | version.json URL 前缀,最终请求 {versionBase}update-notice/version.json。优先级:显式 versionBase → Vite import.meta.env.BASE_URL''。非根路径 / CDN 部署时建议显式配置 | | check | CheckConfig | 见下表 | 版本检查触发策略 | | microApp | MicroAppConfig | — | 微前端场景配置 | | themeAdapter | ThemeAdapterConfig | { type: 'antd' } | 默认 UI 主题适配 | | placement | ```typescript 'topLeft' | 'topRight' | 'bottomLeft' | | forcedUpdate | boolean | false | true 时强制更新:无「稍后」按钮,有遮罩不可操作 | | locale | LocaleConfig | — | 按语言覆盖内置通知文案;整站当前语言由 setLocale 控制,内置默认 zh_CN en_US | | disableNotification | boolean | false | true 时完全关闭该应用的检查 / 默认 UI / 消息通知web_update_notice,纯壳 Host 常用。与 hiddenDefaultNotice 互斥,不得同时为 true | | hiddenDefaultNotice | boolean | false | true 时关闭默认 UI,仍检查并派发 web_update_notice,供业务自定义 UI。与 disableNotification 互斥,不得同时为 true |

通知模式三选一:默认 UI(两者均不开启)/ 仅 disableNotification / 仅 hiddenDefaultNotice

check

| 字段 | 类型 | 默认 | 说明 | | ----------------- | --------- | ---------------- | ------------------------------ | | interval | number | 10 * 60 * 1000 | 轮询间隔(毫秒);<= 0 不轮询 | | onWindowActive | boolean | true | 窗口重新获得焦点时检查 | | onTabVisible | boolean | true | 标签页从隐藏变为可见时检查 | | onResourceError | boolean | true | 静态资源加载失败时检查(用于发现发版后旧 chunk 失效) |

microApp

| 字段 | 类型 | 默认 | 说明 | | --------- | --------- | --- | ------------------------------------------- | | enabled | boolean | — | 是否启用微前端口径;为 true 时需配合 Host setActiveApp | | appId | string | — | 当前应用 ID;仅当该 ID 为 active app 时才会检查 / 通知 |

themeAdapter

| 字段 | 类型 | 默认 | 说明 | | -------------- | ------- | -------------------------------- | -------- | | type | 'antd' | 'cssVariable' | 'antd' | | primaryColor | string | { light: string; dark: string } | — |

locale

按语言覆盖文案,键为 'zh_CN' | 'en_US',值为部分字段:

| 字段 | 说明 | | ------------------- | ---------- | | title | 通知标题 | | description | 可选更新时的说明文案 | | buttonText | 「立即刷新」按钮文案 | | dismissButtonText | 「稍后」按钮文案 | | forcedDescription | 强制更新正文 |

createUpdateNotice({
  // 非根目录部署或者部署在cdn服务上
  versionBase: '/admin/',
  // 自定义版本检查时间,5min中检查一次版本
  check: { interval: 5 * 60 * 1000 },
  // 弹窗位置 
  placement: 'bottomRight',
  // 是否强制更新
  forcedUpdate: false,
  // 自定义主题色
  themeAdapter: {
    type: "cssVariable",
    // 不写 primaryColor:通知主色走默认 CSS / 业务侧 --update-* 覆盖
    // primaryColor: '#dddccc',
    primaryColor: {
      light: "#dddccc",
      dark: "#eeeeff",
    },
  },
  //自定义文案
  locale: {
    zh_CN: { 
        title: '发现新版本',
        description:'检测到新版本啦', 
        buttonText: '立即刷新', 
        dismissButtonText:'忽略',
        forcedDescription:'检测到新版本啦,请刷新页面'
    },
    en_US: { 
        title: 'Update available', 
        description:'A new version has been detected', 
        buttonText: 'Refresh' 
        dismissButtonText: 'Later', 
        forcedDescription:'A new version has been detected; please refresh the page.' 
},
  },
})

VersionPluginOptions

构建侧配置,传给 vitePluginVersion(options?) / defaultPluginVersion(options?)。只生成 {outDir}/update-notice/version.json,不注入 HTML / 脚本。Runtime 配置这些字段。

| 字段 | 类型 | 默认 | 说明 | | ------------- | ------------ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------ | | versionType | 'timestamp' | 'gitcommit' | 'version' | | outDir | string | 见下 | 产物根目录,最终写出 {outDir}/update-notice/version.jsonvitePluginVersion 未配置时读 Vite build.outDirdefaultPluginVersion 未配置时为 'dist' |

versionType

| 值 | 说明 | | ----------- | ------------------------------------------------------------- | | timestamp | 构建时间戳(Date.now()),默认推荐 | | gitcommit | 短 Git Commit(git rev-parse --short HEAD);获取失败时降级为 timestamp | | version | 当前 package.jsonversion;获取失败时降级为 timestamp |

// vite.config.ts
vitePluginVersion({
  versionType: 'gitcommit',
  // outDir 一般可省略,自动用 Vite build.outDir
})

// 其他构建工具
await defaultPluginVersion({
  versionType: 'version',
  outDir: 'build',
})

本地示例

pnpm install
pnpm build
pnpm dev:vite   # Host http://localhost:7100 · 单体 http://localhost:7103

更多示例见 docs/examples.md