Registry / testing / vite-plugin-browserslist-useragent

vite-plugin-browserslist-useragent

JSON →
library0.7.0jsnpmunverified

A Vite plugin that wraps browserslist-useragent-regexp to compile browserslist queries into RegExp patterns for testing browser user agents. Current stable version is 0.7.0, updated regularly. It automatically generates a virtual module (virtual:supported-browsers) that exposes the compiled regexes, eliminating the need to run CLI commands manually. Key differentiator: seamless integration with Vite's build pipeline, with support for Vite 3 through 8. Ships TypeScript definitions.

npm install vite-plugin-browserslist-useragent
INSTALL
IMPORT
SIG · VITE-PLUGIN-BROWSE
V
vite-plugin-browserslist-useragent
testingjavascriptv0.7.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

SupportedBrowsers
import SupportedBrowsers from 'vite-plugin-browserslist-useragent'
import { SupportedBrowsers } from 'vite-plugin-browserslist-useragent'
Default export; named import will fail. TypeScript: use default import.
browsersRegex
import { browsersRegex } from 'virtual:supported-browsers'
import { browsersRegex } from 'vite-plugin-browserslist-useragent'
Exposed via virtual module, not from the plugin package itself.
browsersRegexes
import { browsersRegexes } from 'virtual:supported-browsers'
import { browsersRegexes } from 'vite-plugin-browserslist-useragent'
Also exposed via virtual module.
SupportedBrowsers
const SupportedBrowsers = require('vite-plugin-browserslist-useragent')
const { SupportedBrowsers } = require('vite-plugin-browserslist-useragent')
CJS: default export via module.exports, not named export.

Shows how to install the plugin, add it to Vite config, and use the virtual module to test browser support via userAgent regex.

// vite.config.ts import { defineConfig } from 'vite'; import SupportedBrowsers from 'vite-plugin-browserslist-useragent'; export default defineConfig({ plugins: [SupportedBrowsers()], }); // In your app code (e.g., main.ts) import { browsersRegex } from 'virtual:supported-browsers'; const isSupported = browsersRegex.test(navigator.userAgent); console.log('Browser supported:', isSupported);
Debug
Known issues
gotchaThe virtual module 'virtual:supported-browsers' is auto-generated and not a real file. TypeScript may complain about missing module declaration.
fix
Add a module declaration file: declare module 'virtual:supported-browsers' { export const browsersRegex: RegExp; export const browsersRegexes: Array<{family: string; regexString: string; requestVersionsStrings: string[]}>; }
affects: >=0.0.0
gotchaPlugin options must be passed as object; omitting options uses defaults. Some options require specific browserslist-useragent-regexp version compatibility.
fix
Refer to the browserslist-useragent-regexp documentation for valid options. Example: SupportedBrowsers({ browsers: 'last 2 versions', env: 'production' })
affects: >=0.0.0
gotchaThe plugin depends on a browserslist configuration file (.browserslistrc) or a 'browserslist' key in package.json. Without it, no regexes may be generated.
fix
Create a .browserslistrc file in your project root with your desired browser queries (e.g., 'last 2 versions', 'not dead').
affects: >=0.0.0
breakingVersion 0.7.0 dropped support for Vite 2. Peer dependency now requires Vite ^3.0.0 || ^4.0.0 || ^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0.
fix
Upgrade to Vite 3+ or stay on an older version of this plugin (<0.7.0) if using Vite 2.
affects: >=0.7.0
Errors
Common errors & fixes
Error: Cannot find module 'virtual:supported-browsers' or its corresponding type declarations.
TypeScript cannot resolve the virtual module without a declaration file.
fix
Create a .d.ts file (e.g., src/vite-env.d.ts) with: declare module 'virtual:supported-browsers' { export const browsersRegex: RegExp; export const browsersRegexes: any[]; }
TypeError: Cannot destructure property 'browsersRegex' of '...' as it is undefined.
Attempting named import from the plugin package instead of the virtual module.
fix
Use import SupportedBrowsers from 'vite-plugin-browserslist-useragent' for the plugin, and import { browsersRegex } from 'virtual:supported-browsers' for the regex.
Error: Browserslist config not found. Create a .browserslistrc file or set browserslist in package.json.
The plugin requires a browserslist configuration to generate regexes.
fix
Create a .browserslistrc file in the project root with your target browsers, e.g.:
last 2 versions
not dead
Upgrade
Version history
0.7.0latest on npm
Audit
Dependencies
viterequiredpeer dependency required for plugin to work
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
vite-plugin-browserslist-useragent — npm install vite-plugin-browserslist-useragent · libregistry