generated from sindresorhus/node-module-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 7
/
readme.md
77 lines (49 loc) · 2.23 KB
/
readme.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# browserslist-to-esbuild
> Use [browserslist](https://github.com/browserslist/browserslist) with [esbuild](https://esbuild.github.io/).
Allows you to use use browserslist and pass the correct browsers to esbuild's [target](https://esbuild.github.io/api/#target) option.
## Install
Make sure you have `browserslist` already installed in your project, then:
```
npm install --save-dev browserslist-to-esbuild
```
or
```
yarn add --dev browserslist-to-esbuild
```
## Usage
You can call `browserslistToEsbuild()` directly in your `esbuild.mjs` script, it will look for your browserslist config in either `package.json` or the `.browserslistrc`.
It will return an esbuild-compatible array of browsers.
```js
import { build } from 'esbuild'
import browserslistToEsbuild from 'browserslist-to-esbuild'
await build({
entryPoints: ['input.js'],
outfile: 'output.js',
bundle: true,
target: browserslistToEsbuild(), // --> ["chrome79", "edge92", "firefox91", "safari13.1"]
})
```
Otherwise, you can pass yourself a browserslist array or string to the function.
```js
browserslistToEsbuild(['>0.2%', 'not dead', 'not op_mini all'])
```
## API
### browserslistToEsbuild(browserslistConfig?, options?)
#### browserslistConfig
Type: `array | string | undefined`
An array of string of browsers [compatible with browserslist](https://github.com/browserslist/browserslist#full-list). If none is passed, a browserslist config is searched in the script running directory.
#### options
Type: `object | undefined`
An object containing the options that will be forwarded to browserslist. You can check out the [browserslist options documentation](https://github.com/browserslist/browserslist?tab=readme-ov-file#js-api) to see all the options available.
## CLI
You can also use this package on the cli to test out the command in your project.
If no argument is passed, the browserslist config is searched in the script running directory.
Here is some example usage:
```bash
$ npx browserslist-to-esbuild
chrome109 edge118 firefox115 ios15.6 opera102 safari15.6
$ npx browserslist-to-esbuild '>0.2%, not dead'
chrome103 edge87 firefox115 ios12.2 opera102 safari14.1
$ npx browserslist-to-esbuild '>0.2%' 'not dead'
chrome103 edge87 firefox115 ios12.2 opera102 safari14.1
```