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-useragentVerified import paths — ran on the pinned version, not inferred.
Shows how to install the plugin, add it to Vite config, and use the virtual module to test browser support via userAgent regex.
Add a module declaration file: declare module 'virtual:supported-browsers' { export const browsersRegex: RegExp; export const browsersRegexes: Array<{family: string; regexString: string; requestVersionsStrings: string[]}>; }Refer to the browserslist-useragent-regexp documentation for valid options. Example: SupportedBrowsers({ browsers: 'last 2 versions', env: 'production' })Create a .browserslistrc file in your project root with your desired browser queries (e.g., 'last 2 versions', 'not dead').
Upgrade to Vite 3+ or stay on an older version of this plugin (<0.7.0) if using Vite 2.
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[]; }Use import SupportedBrowsers from 'vite-plugin-browserslist-useragent' for the plugin, and import { browsersRegex } from 'virtual:supported-browsers' for the regex.Create a .browserslistrc file in the project root with your target browsers, e.g.: last 2 versions not dead