How to use browserslist

Comprehensive browserslist code examples:

How to use browserslist.default:

189
190
191
192
193
194
195
196
197
198
const shouldSearchForConfig = !options.ignoreBrowserslistConfig && !hasTargets;

if (!browsers && shouldSearchForConfig) {
  var _browserslist$loadCon;

  browsers = (_browserslist$loadCon = _browserslist.default.loadConfig({
    config: options.configFile,
    path: options.configPath,
    env: options.browserslistEnv
  })) != null ? _browserslist$loadCon : [];

How to use browserslist.coverage:

51
52
53
54
55
56
57
58
59
60
  let list = versions[browser]
  list = list.sort((a, b) => parseFloat(b) - parseFloat(a))
  out += `  ${browser}: ${list.join(', ')}\n`
}

let coverage = browserslist.coverage(prefixes.browsers.selected)
let round = Math.round(coverage * 100) / 100.0
out += `\nThese browsers account for ${round}% of all users globally\n`

let atrules = []

How to use browserslist.findConfig:

34
35
36
37
38
39
40
41
42
43
if (path.isAbsolute(input)) {
	const [, configPath, env] = inputRx.exec(input) || [];
	return { configPath, env };
}

const config = browserslist.findConfig(context);

if (config && Object.keys(config).includes(input)) {
	return { env: input };
}

How to use browserslist.defaults:

153
154
155
156
157
158
159
160
161
162
163
164
plugin.data = autoprefixerData


/**
 * Autoprefixer default browsers
 */
plugin.defaults = browserslist.defaults


/**
 * Inspect with default Autoprefixer
 */

How to use browserslist.loadConfig:

17
18
19
20
21
22
23
24
25
26
27
28
const topLevelFrameworkPaths = isDevelopment ? [] : getTopLevelFrameworkPaths(__dirname);
const isAnalyze = !!process.env.ANALYZE;
const cpuCount = require('os').cpus().length;
const context = __dirname;


const targets = browserslist.loadConfig({ path: context});


/** @type {import('webpack').Configuration} */
const config = {
  mode: isDevelopment ? 'development' : 'production',