Skip to content
开发文档
Configuration
支持的浏览器

支持的浏览器

¥Supported Browsers

v1.1.10 开始,你现在可以使用 browserslist 自动配置支持的浏览器。

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

用法

¥Usage

.swcrc
{
  "env": {
    "targets": {
      "chrome": "79"
    },
    "mode": "entry",
    "coreJs": "3.22"
  }
}

选项

¥Options

targets

string | Array<string> | { [string]: string },默认为 {}

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

描述你的项目支持/目标的环境。这可以是 browserslist-compatible (opens in a new tab) 查询 (有限制) (opens in a new tab)

¥Describes the environments you support/target for your project. This can either be a browserslist-compatible (opens in a new tab) query (with limitations) (opens in a new tab):

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

或者支持的最低环境版本的对象:

¥Or an object of minimum environment versions to support:

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

示例环境:

¥Example environments:

  • chrome

  • opera

  • edge

  • firefox

  • safari

  • ie

  • ios

  • android

  • node

  • electron

如果未指定 targets,SWC 将使用 browserslist 来获取目标信息。

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

path

  • string,默认为当前目录。

    ¥string, defaults to current directory.

  • path 指定加载 browserslist 模块和任何 browserslist 配置文件的目录。例如,package.json 中的 .browserslistrcbrowserslist 字段。如果你的构建系统不在项目的根目录中,这可能很有用。

    ¥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

⚠️

usage 模式目前不如 Babel 高效,如果你有像 "foo"["a" + "t"]() 这样的用法。SWC 不会计算表达式 "a" + "t",也不会包含 String.prototype.at polyfill。

¥The usage mode is currently not as efficient as Babel, iff you have a usage like "foo"["a" + "t"](). SWC does not evaluate the expression "a" + "t" and will not include the String.prototype.at polyfill.

skip

定义要跳过的 ES 功能以减少包大小。例如,你的 .swcrc 可能是:

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

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

coreJs

  • string,默认为 undefined

    ¥string, defaults to undefined.

  • coreJs 指定要使用的 core-js 版本,可以是 swc 支持的任何 core-js 版本。例如,"3.22"

    ¥coreJs specifies the version of core-js to use, can be any core-js versions supported by swc. E.g., "3.22".

该选项与 mode: "usage"mode: "entry" 一起使用时有效。建议指定次要版本(例如 "3.22"),否则 "3" 将被解释为 "3.0",其中可能不包含最新功能的填充。

¥The option has an effect when used alongside mode: "usage" or mode: "entry". It is recommended to specify the minor version (E.g. "3.22") otherwise "3" will be interpreted as "3.0" which may not include polyfills for the latest features.

其他选项

¥Additional Options

  • debug:(布尔值)默认为 false

    ¥debug: (boolean) defaults to false.

  • dynamicImport:(布尔值)默认为 false

    ¥dynamicImport: (boolean) defaults to false.

  • loose:(布尔值)默认为 false。为任何允许它们的插件启用 松散变换

    ¥loose: (boolean) defaults to false. Enable loose transformations for any plugins that allow them.

  • include:(string[]) 可以是 core-js 模块 (es.math.sign) 或 SWC 通行证 (transform-spread)。

    ¥include: (string[]) can be a core-js module (es.math.sign) or an SWC pass (transform-spread).

  • exclude:(string[]) 可以是 core-js 模块 (es.math.sign) 或 SWC 通行证 (transform-spread)。

    ¥exclude: (string[]) can be a core-js module (es.math.sign) or an SWC pass (transform-spread).

  • shippedProposals:(布尔值)默认为 false

    ¥shippedProposals: (boolean) defaults to false.

  • forceAllTransforms:(布尔值)默认为 false。启用所有可能的转换。

    ¥forceAllTransforms: (boolean) defaults to false. Enable all possible transforms.

Last updated on November 24, 2023