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 🙏

© 2024 – Pkg Stats / Ryan Hefner

detection-version

v1.0.4

Published

用于前端(客户端)检测生产版本更新的检测工具

Downloads

7

Readme

介绍说明

此插件作用:通过前端来控制版本检测的工具,主要是为了解决前端 dist 包更新到服务器后,客户端正在使用前端页面,导致页丢失的问题,所以可以通过该插件检测到版本更新后,执行回调,提示用户更新页面、强制刷新页面等操作。 原理是采用的 轮询机制,通过轮询查询前端打包工具生成的 js 版本号进行比对,使用浏览器 localStroage API 进行版本号存储,当版本号发生变化时,执行回调。

安装

npm install detection-version

导入

import detectVersion from "detection-version";

页面 dom 生成后调用

/**
 * open: boolean; 是否开启版本检测, 为true开启检测
 */
/**
 * path?: string;部署路径的前缀 如果静态资源地址有前缀,则需要传入
 */
/**
 * duration: number; 轮询查询间隔 单位ms 默认每五秒进行一次比对
 */

/**
 * func:function;  检测到版本更新后的执行回调,如果不传 默认执行提示弹窗
 */
detectVersion({
  open: true,
  duration: 5000,
  path: "/h5/", //例如部署到了10.200.1.15:8080/h5/
  func: () => {
    // 这里执行 版本更新检测到后 你的逻辑
    const result = confirm("有新功能发布,请点击确定刷新页面!");
    if (result) {
      location.reload(); //强制刷新 清除缓存
    }
  },
});

示例 vue 模版

// 在main.js 中引入
import "./style.css";
import { createApp } from "vue";
import App from "./App.vue";
import detectVersion from "detection-version";

detectVersion({
  open: true, //这块建议 从.env 文件中读取 如果是发版到服务器后 开启检测, 本地开发直接关闭即可 不然热更新会阻碍开发
  duration: 5000,
  func: () => {
    const result = confirm("有新功能发布,请点击确定刷新页面!");
    if (result) {
      location.reload(); //强制刷新 清除缓存
    }
  },
});
const app = createApp(App);
app.mount("#app");

注意事项

APP 端目前没有测试使用 ,主要还是用在 pc 端,因为目前使用的浏览器 localStroage 存储的版本号,所以 APP 端需要自己实现版本号存储,目前没有测试使用

开源协议

ISC