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

tdft-vite-plugin-build-version

v1.0.1

Published

前端自动刷新页面 vite 插件

Readme

@tdft/vite-plugin-build-version

天道金科前端自动刷新页面 vite 插件。

背景

前端每次发布都会生成新的资源(JS、CSS、图片),删除旧的资源,而停留在旧的页面只能加载旧的资源,而旧资源可能已经被删除了,所以可能会出现无法加载的情况。

而因为前端使用了懒加载提升页面加载性能,只有发生跳转时才会去请求对应页面的资源,也就表现为路由跳转失败。

之前的处理方式是在资源加载失败时提示用户刷新页面,这样对用户来说体验不好,所以需要想办法优化逻辑。

考虑到我们一般在晚上发布,而一晚上过去 token 过期需要重新登录,如果在用户登录时判断有没有新版本,有就强制刷新页面再进入系统,这样可以避免大多数因为发布新旧资源导致的问题。 之前已经在资源加载失败时添加了错误提示,让用户刷新页面加载新的 html 文件从而使用新的资源。

这就是开发这个插件的原因。

使用方式

这个插件包含两部分,一部分是 Vite 插件,另一部分是浏览器方法,内置了部分功能。

Vite 插件

import { buildVersionPlugin } from '@tdft/vite-plugin-build-version/plugin'

plugins: [
  buildVersionPlugin()
]

浏览器方法

import { checkBuildVersion, redirectTo } from '@tdft/vite-plugin-build-version'
 
// 建议用法
checkBuildVersion().then(({ status }) => {
  if (!status) {
    redirectTo()
  }
  
  // other things
})

如果不满足需求,可以自己写处理逻辑,可以从 window.buildVersion 获得当前版本,通过请求项目目录的 version.json 文件获得最新版本。

注意:暂时不支持 history 路由方式,如有项目需要,可联系 @王悦天 添加。