{"id":22969104,"url":"https://github.com/wx-dongxing/unplugin-detect-update","last_synced_at":"2026-04-13T01:05:38.812Z","repository":{"id":65601792,"uuid":"587121629","full_name":"WX-DongXing/unplugin-detect-update","owner":"WX-DongXing","description":"Detect web app version update for Vite, Webpack and Rollup","archived":false,"fork":false,"pushed_at":"2023-01-31T09:38:43.000Z","size":101,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T23:33:53.957Z","etag":null,"topics":["plugins","rollup","unplugin","update","version","vite","webpack"],"latest_commit_sha":null,"homepage":"https://detect-update-vite-app-ifyh.vercel.app/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WX-DongXing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2023-01-10T02:16:04.000Z","updated_at":"2023-12-26T07:28:39.000Z","dependencies_parsed_at":"2023-02-16T17:46:19.707Z","dependency_job_id":null,"html_url":"https://github.com/WX-DongXing/unplugin-detect-update","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WX-DongXing%2Funplugin-detect-update","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WX-DongXing%2Funplugin-detect-update/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WX-DongXing%2Funplugin-detect-update/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WX-DongXing%2Funplugin-detect-update/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WX-DongXing","download_url":"https://codeload.github.com/WX-DongXing/unplugin-detect-update/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246761478,"owners_count":20829467,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["plugins","rollup","unplugin","update","version","vite","webpack"],"created_at":"2024-12-14T21:32:13.470Z","updated_at":"2026-04-13T01:05:38.759Z","avatar_url":"https://github.com/WX-DongXing.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# unplugin-detect-update\n\n[![NPM version](https://img.shields.io/npm/v/unplugin-detect-update?color=a1b858\u0026label=)](https://www.npmjs.com/package/unplugin-detect-update)\n\nDetect web app version update for Vite, Webpack and Rollup. Powered by [unplugin](https://github.com/unjs/unplugin).\n\n---\n\n## Install\n\n```bash\nnpm i unplugin-detect-update -D\n```\n\n\u003cdetails\u003e\n\u003csummary\u003eVite\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// vite.config.ts\nimport DetectUpdate from 'unplugin-detect-update/vite'\n\nexport default defineConfig({\n  plugins: [\n    DetectUpdate({\n      /* options */\n    }),\n  ],\n})\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eRollup\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// rollup.config.js\nimport DetectUpdate from 'unplugin-detect-update/rollup'\n\nexport default {\n  plugins: [\n    DetectUpdate({\n      /* options */\n    }),\n  ],\n}\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eWebpack\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// webpack.config.js\nmodule.exports = {\n  /* ... */\n  plugins: [\n    require('unplugin-detect-update/webpack')({\n      /* options */\n    }),\n  ],\n}\n```\n\n\u003e This module works for Webpack \u003e= 3\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eNuxt\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// nuxt.config.js\nexport default {\n  buildModules: [\n    [\n      'unplugin-detect-update/nuxt',\n      {\n        /* options */\n      },\n    ],\n  ],\n}\n```\n\n\u003e This module works for both Nuxt 2 and [Nuxt Vite](https://github.com/nuxt/vite)\n\n\u003cbr\u003e\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eVue CLI\u003c/summary\u003e\u003cbr\u003e\n\n```ts\n// vue.config.js\nmodule.exports = {\n  configureWebpack: {\n    plugins: [\n      require('unplugin-detect-update/webpack')({\n        /* options */\n      }),\n    ],\n  },\n}\n```\n\n\u003cbr\u003e\u003c/details\u003e\n\n## Usage\n\n```ts\nimport { useDetectUpdate } from 'unplugin-detect-update/hooks'\n\nconst { start, cancel, detect, onUpdate } = useDetectUpdate({\n  immediate: true,\n  worker: false,\n  ms: 5 * 60000,\n  trigger: ['visibility', 'focus'],\n})\n\nonUpdate(val =\u003e {\n  console.log('update: ', val)\n})\n```\n\nThe `version` will be added to the `body` in each html file after build, and also stored in session, key was `detect-update-store`\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\" /\u003e\n    \u003clink rel=\"icon\" href=\"/favicon.ico\" /\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" /\u003e\n  \u003c/head\u003e\n  \u003cbody version=\"0.1.0\"\u003e\n    \u003cdiv id=\"app\"\u003e\u003c/div\u003e\n    ...\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Configuration\n\n```ts\n// plugin config\nDetectUpdate({\n  // the name of generated version record file\n  fileName: 'version.json',\n  // the type of generated version\n  type: 'commit',\n  worker: {\n    // whether to generate worker file\n    enable: true,\n    // worker file name\n    fileName: 'worker.js',\n  },\n  // extra data in version.json\n  extra: {},\n})\n```\n\n## Types\n\n**Plugin types**\n\n```ts\n/**\n * As type as version, package.json file version field or last commit id or current timestamp\n */\nexport type VersionType = 'package' | 'commit' | 'timestamp'\n\nexport interface WorkerOption {\n  /**\n   * Whether to generate worker file\n   *\n   * @default true\n   */\n  enable?: boolean\n  /**\n   * The name of generated worker file\n   *\n   * @default worker.js\n   */\n  fileName?: string\n}\n\nexport interface Options {\n  /**\n   * The name of generated version record file\n   *\n   * @default version.json\n   */\n  fileName?: string\n  /**\n   * The type of generated version, will be set to 'package' in development mode, and set the 'version' field in package.json under the current directory to the version\n   *\n   * @default commit\n   */\n  type?: VersionType\n  /**\n   * Worker Options\n   *\n   * @default true\n   */\n  worker?: boolean | WorkerOption\n  /**\n   * extra data in version.json\n   *\n   * @default {}\n   */\n  extra?: Record\u003cstring, any\u003e\n}\n```\n\n**UseDetectUpdate types**\n\n```ts\n/**\n * Extra detect trigger type, trigger detection when window focused or visible\n */\nexport type Trigger = 'focus' | 'visibility'\n\nexport interface UseDetectUpdateOptions {\n  /**\n   * Execute the detect immediately on calling\n   * @default true\n   */\n  immediate?: boolean\n  /**\n   * Whether use worker, not work in development mode\n   * @default false\n   */\n  worker?: boolean\n  /**\n   * cycle time, ms\n   * @default 5 * 60000\n   */\n  ms?: number\n  /**\n   * Extra detect trigger types\n   * @default []\n   */\n  trigger?: Trigger[]\n}\n\nexport interface UseDetectUpdateReturn {\n  /**\n   * Cancel detect on calling\n   */\n  cancel: () =\u003e void\n  /**\n   * Start detect on calling\n   */\n  start: () =\u003e void\n  /**\n   * Active trigger version detection\n   */\n  detect: () =\u003e void\n  /**\n   * Called when version changed\n   */\n  onUpdate: EventHookOn\u003cany\u003e\n}\n```\n\n## License\n\n[MIT](./LICENSE) License © 2023 [Dong Xing](https://github.com/WX-DongXing)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwx-dongxing%2Funplugin-detect-update","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwx-dongxing%2Funplugin-detect-update","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwx-dongxing%2Funplugin-detect-update/lists"}