{"id":13417425,"url":"https://github.com/kingyue737/vite-plugin-browserslist-useragent","last_synced_at":"2025-03-15T02:31:17.093Z","repository":{"id":49401735,"uuid":"517572915","full_name":"kingyue737/vite-plugin-browserslist-useragent","owner":"kingyue737","description":"A utility vite plugin to compile browserslist query to a RegExp to test browser useragent.","archived":false,"fork":false,"pushed_at":"2024-04-21T21:50:54.000Z","size":192,"stargazers_count":13,"open_issues_count":4,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-23T16:15:05.366Z","etag":null,"topics":["browserslist","useragent","vite","vite-plugin"],"latest_commit_sha":null,"homepage":"","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/kingyue737.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-07-25T08:04:26.000Z","updated_at":"2024-04-29T12:31:31.839Z","dependencies_parsed_at":"2024-01-28T12:24:35.061Z","dependency_job_id":"46e35dd6-bdbf-4f04-9865-3dc7f4738781","html_url":"https://github.com/kingyue737/vite-plugin-browserslist-useragent","commit_stats":{"total_commits":32,"total_committers":3,"mean_commits":"10.666666666666666","dds":0.1875,"last_synced_commit":"78439da846d619693793e52e4a9468a6da8daddc"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingyue737%2Fvite-plugin-browserslist-useragent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingyue737%2Fvite-plugin-browserslist-useragent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingyue737%2Fvite-plugin-browserslist-useragent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kingyue737%2Fvite-plugin-browserslist-useragent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kingyue737","download_url":"https://codeload.github.com/kingyue737/vite-plugin-browserslist-useragent/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243674807,"owners_count":20329164,"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":["browserslist","useragent","vite","vite-plugin"],"created_at":"2024-07-30T22:00:37.007Z","updated_at":"2025-03-15T02:31:16.728Z","avatar_url":"https://github.com/kingyue737.png","language":"TypeScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Framework-agnostic Plugins"],"readme":"# vite-plugin-browserslist-useragent\n\n[![npm version](https://img.shields.io/npm/v/vite-plugin-browserslist-useragent)](https://www.npmjs.com/package/vite-plugin-browserslist-useragent)\n[![npm downloads](https://img.shields.io/npm/dm/vite-plugin-browserslist-useragent)](https://www.npmjs.com/package/vite-plugin-browserslist-useragent)\n[![gitmoji](https://img.shields.io/badge/gitmoji-%20😜%20😍-FFDD67.svg)](https://gitmoji.dev)\n\nA vite plugin wrapping [browserslist-useragent-regexp](https://github.com/browserslist/browserslist-useragent-regexp) which provides utility RegExps compiled by [browserslist query](https://github.com/browserslist/browserslist#queries) to test browser useragent.\n\nSimplest example: you can detect supported browsers on client-side.\n\n1. Create `.browserslistrc` config, for example like this:\n\n```\nlast 2 versions\nnot dead\n```\n\n2. Add plugin to `vite.config.*`:\n\n```ts\n// vite.config.ts\nimport SupportedBrowsers from 'vite-plugin-browserslist-useragent'\nexport default defineConfig({\n  plugins: [SupportedBrowsers(/* options */)],\n})\n```\n\n3. Import RegExp from virtual module:\n\n```js\nimport { browsersRegex } from 'virtual:supported-browsers'\n\nif (browsersRegex.test(navigator.userAgent)) {\n  alert('Your browser is supported.')\n}\n```\n\nAuto-generated `virtual:supported-browsers`:\n\n```js\nexport const browsersRegex =\n  /Edge?\\/(10[5-9]|1[1-9]\\d|[2-9]\\d\\d|\\d{4,})(\\.\\d+|)(\\.\\d+|)|Firefox\\/(10[4-9]|1[1-9]\\d|[2-9]\\d\\d|\\d{4,})\\.\\d+(\\.\\d+|)|Chrom(ium|e)\\/(10[5-9]|1[1-9]\\d|[2-9]\\d\\d|\\d{4,})\\.\\d+(\\.\\d+|)|Maci.* Version\\/(15\\.([6-9]|\\d{2,})|(1[6-9]|[2-9]\\d|\\d{3,})\\.\\d+)([,.]\\d+|)( Mobile\\/\\w+|) Safari\\/|Chrome.+OPR\\/(9\\d|\\d{3,})\\.\\d+\\.\\d+|(CPU[ +]OS|iPhone[ +]OS|CPU[ +]iPhone|CPU IPhone OS|CPU iPad OS)[ +]+(15[._]([6-9]|\\d{2,})|(1[6-9]|[2-9]\\d|\\d{3,})[._]\\d+)([._]\\d+|)|Opera Mini|Android:?[ /\\-](10[6-9]|1[1-9]\\d|[2-9]\\d{2}|\\d{4,})(\\.\\d+|)(\\.\\d+|)|Mobile Safari.+OPR\\/(6[4-9]|[7-9]\\d|\\d{3,})\\.\\d+\\.\\d+|Android.+Firefox\\/(10[5-9]|1[1-9]\\d|[2-9]\\d\\d|\\d{4,})\\.\\d+(\\.\\d+|)|Android.+Chrom(ium|e)\\/(10[6-9]|1[1-9]\\d|[2-9]\\d\\d|\\d{4,})\\.\\d+(\\.\\d+|)|Android.+(UC? ?Browser|UCWEB|U3)[ /]?(13\\.([4-9]|\\d{2,})|(1[4-9]|[2-9]\\d|\\d{3,})\\.\\d+)\\.\\d+|SamsungBrowser\\/(1[7-9]|[2-9]\\d|\\d{3,})\\.\\d+|Android.+MQQBrowser\\/(13(\\.([1-9]|\\d{2,})|)|(1[4-9]|[2-9]\\d|\\d{3,})(\\.\\d+|))(\\.\\d+|)|K[Aa][Ii]OS\\/(2\\.([5-9]|\\d{2,})|([3-9]|\\d{2,})\\.\\d+)(\\.\\d+|)/\nexport const browsersRegexes = [\n  {\n    family: 'edge',\n    sourceRegex: {},\n    sourceRegexString: 'Edge?\\\\/(\\\\d+)(\\\\.(\\\\d+)|)(\\\\.(\\\\d+)|)',\n    regex: {},\n    requestVersions: [\n      [105, 0, 0],\n      [106, 0, 0],\n    ],\n    requestVersionsStrings: ['105.0.0', '106.0.0'],\n    regexString: 'Edge?\\\\/(105|106)(\\\\.0|)(\\\\.\\\\d+|)',\n  },\n  /* ... */\n]\n```\n\n## Install\n\n```bash\npnpm add -D vite-plugin-browserslist-useragent\n# or\nnpm i -D vite-plugin-browserslist-useragent\n# or\nyarn add -D vite-plugin-browserslist-useragent\n```\n\n## Why?\n\nhttps://github.com/browserslist/browserslist-useragent-regexp#why\n\n### Why wrap `browserslist-useragent-regexp` with vite plugin?\n\nLet [Vite](https://github.com/vitejs/vite) transform and bundle for you and no need to run CLI every time you change browserslist.\n\n## Virtual Module\n\nVirtual module `virtual:supported-browsers` exposes two variables returned by the following two methods of `browserslist-useragent-regexp` whose arguments are passed from plugin's [options](#options):\n\n### [getUserAgentRegex(options)=\u003e browsersRegexp: RegExp](https://browserslist.github.io/browserslist-useragent-regexp/functions/getUserAgentRegex.html)\n\nCompile browserslist query to one regex.\n\n### [getUserAgentRegexs(options)=\u003e browsersRegexps: BrowserVersionedRegex[]](https://browserslist.github.io/browserslist-useragent-regexp/functions/getUserAgentRegexes.html)\n\nCompile browserslist query to [regexes for each browser](#regexp-info-object).\n\n#### Options\n\n| Option               | Type                 | Default | Description                                                                                                                                              |\n| -------------------- | -------------------- | ------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| browsers             | `string \\| string[]` | —       | Manually provide a browserslist query (or an array of queries). Specifying this overrides the browserslist configuration specified in your project.      |\n| env                  | `string`             | —       | When multiple browserslist [environments](https://github.com/ai/browserslist#environments) are specified, pick the config belonging to this environment. |\n| ignorePatch          | `boolean`            | `true`  | Ignore differences in patch browser numbers.                                                                                                             |\n| ignoreMinor          | `boolean`            | `false` | Ignore differences in minor browser versions.                                                                                                            |\n| allowHigherVersions  | `boolean`            | `false` | For all the browsers in the browserslist query, return a match if the useragent version is equal to or higher than the one specified in browserslist.    |\n| allowZeroSubversions | `boolean`            | `false` | Ignore match of patch or patch and minor, if they are 0.                                                                                                 |\n\n#### RegExp info object\n\n| Property        | Type                               | Description                                        |\n| --------------- | ---------------------------------- | -------------------------------------------------- |\n| family          | `string`                           | Browser family.                                    |\n| requestVersions | `[number, number, number][]`       | Versions provided by browserslist.                 |\n| regex           | `RegExp`                           | Regex to match useragent with family and versions. |\n| sourceRegex     | `RegExp`                           | Original useragent regex, without versions.        |\n| version         | `[number, number, number] \\| null` | Useragent version of regex.                        |\n| minVersion      | `[number, number, number] \\| null` | Useragent min version of regex.                    |\n| maxVersion      | `[number, number, number] \\| null` | Useragent max version of regex.                    |\n\n### Client Types\n\nIf you want type definition of `virtual:supported-browsers`, add `vite-plugin-browserslist-useragent/client` to `compilerOptions.types` of your `tsconfig`:\n\n```json\n{\n  \"compilerOptions\": {\n    \"types\": [\"vite-plugin-browserslist-useragent/client\"]\n  }\n}\n```\n\n## License\n\n[MIT](./LICENSE) License © 2022 Yue JIN\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingyue737%2Fvite-plugin-browserslist-useragent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkingyue737%2Fvite-plugin-browserslist-useragent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkingyue737%2Fvite-plugin-browserslist-useragent/lists"}