Skip to content
开发文档
Configuration
.swcrc

配置 SWC

¥Configuring SWC

SWC 可以使用 .swcrc 文件进行配置。

¥SWC can be configured with an .swcrc file.

汇编

¥Compilation

使用 SWC 进行开箱即用的编译,不需要定制。你也可以选择覆盖该配置。以下是默认值:

¥Compilation works out of the box with SWC and does not require customization. Optionally, you can override the configuration. Here are the defaults:

.swcrc
{
  "$schema": "https://json.schemastore.org/swcrc",
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false,
      "dynamicImport": false,
      "privateMethod": false,
      "functionBind": false,
      "exportDefaultFrom": false,
      "exportNamespaceFrom": false,
      "decorators": false,
      "decoratorsBeforeExport": false,
      "topLevelAwait": false,
      "importMeta": false
    },
    "transform": null,
    "target": "es5",
    "loose": false,
    "externalHelpers": false,
    // Requires v1.2.50 or upper and requires target to be es2016 or upper.
    "keepClassNames": false
  },
  "minify": false
}

了解有关 配置编译 的更多信息。

¥Read more about configuring compilation.

支持的浏览器

¥Supported Browsers

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

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

用法

¥Usage

首先,安装 browserslist。然后,更新你的 .swcrc

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

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

了解有关 配置支持的浏览器 的更多信息。

¥Read more about configuring supported browsers.

模块

¥Modules

了解有关 配置模块 的更多信息。

¥Read more about configuring modules.

压缩

¥Minification

v1.2.67 开始,你可以通过在 .swcrc 文件中启用 minify 来配置 SWC 以缩小代码:

¥Starting with v1.2.67, you can configure SWC to minify your code by enabling minify in your .swcrc file:

.swcrc
{
  "minify": true
}

了解有关 配置 JavaScript 压缩器 的更多信息。

¥Read more about configuring the JavaScript minifier.

Last updated on November 24, 2023