esbuild-plugin-browserslist
Configure esbuild's target based on a browserslist query
Installation
yarn add esbuild-plugin-browserslist esbuild browserslist
Usage
import esbuild from "esbuild";
import browserslist from "browserslist";
import {
esbuildPluginBrowserslist,
resolveToEsbuildTarget,
} from "esbuild-plugin-browserslist";
await esbuild.build({
entryPoints: ["./foo/bar.ts"],
plugins: [
esbuildPluginBrowserslist(browserslist("defaults"), {
printUnknownTargets: false,
}),
],
});
const target = resolveToEsbuildTarget(browserslist("defaults"), {
printUnknownTargets: false,
});
await esbuild.build({
entryPoints: ["./foo/bar.ts"],
target,
});
:information_source: CJS usage instructions
Adjust the imports as follows:
const esbuild = require("esbuild");
const browserslist = require("browserslist");
const {
esbuildPluginBrowserslist,
resolveToEsbuildTarget,
} = require("esbuild-plugin-browserslist");
Caveats
- Only
edge
, firefox
, chrome
, safari
, ios_saf
, and node
have direct equivalents for esbuild targets. android
and and_chr
are mapped to the chrome
target, and and_ff
is mapped to the firefox
target.- All other browsers are ignored (
and_qq
, samsung
, opera
, op_mini
, op_mob
, ie
, ie_mob
, bb
, baidu
, and kaios
)
Debugging
You can turn on debug logs (which will print all resolutions or failures) using DEBUG=esbuild-plugin-browserslist