Skip to content

Supported Browsers

Starting with v1.1.10, you can now use browserslist to automaticallly configure supported browsers.

Usage

First, install browserslist. Then, update your .swcrc:

{
"env": {
"targets": {
"chrome": "79"
},
"mode": "entry",
"coreJs": 3
}
}

Options

browserslist

If you want to use browserlists with SWC, omit targets in your .swcrc:

{
"env": {
"coreJs": 3
}
}

browserlists can be configured in multiple ways:

  • .browserslistrc
  • browserslist field in package.json

You can use path to specify a custom path to load these configuration files.

targets

string | Array<string> | { [string]: string }, defaults to {}.

Describes the environments you support/target for your project. This can either be a browserslist-compatible query:

{
"env": {
"targets": "> 0.25%, not dead"
}
}

Or an object of minimum environment versions to support:

{
"env": {
"targets": {
"chrome": "58",
"ie": "11"
}
}
}

Example environments:

  • chrome
  • opera
  • edge
  • firefox
  • safari
  • ie
  • ios
  • android
  • node
  • electron

If targets is not specified, SWC uses browserslist to get target information.

path

  • string, defaults to current directory.
  • path specifies the directory to load the browserslist module and any browserslist configuration files. For example, .browserslistrc or browserslist field in package.json. This can be useful if your build system isn't in the root of your project.

mode

  • string, defaults to undefined.
  • Possible values: usage, entry, undefined (this matches useBuiltIns from Babel)
⚠️

The usage mode is currently not as efficient as Babel, yet.

skip

Define ES features to skip to reduce bundle size. For example, your .swcrc could be:

{
"env": {
"skip": ["core-js/modules/foo"]
}
}

Additional Options

  • debug: (boolean) defaults to false.
  • dynamicImport: (boolean) defaults to false.
  • loose: (boolean) defaults to false. Enable loose transformations for any plugins that allow them.
  • include: (string[]) can be a core-js module (es.math.sign) or an SWC pass (transform-spread).
  • exclude: (string[]) can be a core-js module (es.math.sign) or an SWC pass (transform-spread).
  • coreJs: (string) defaults to undefined. The version of core-js to use.
  • shippedProposals: (boolean) defaults to false.
  • forceAllTransforms: (boolean) defaults to false. Enable all possible transforms.