支持的浏览器
¥Supported Browsers
从 v1.1.10 开始,你现在可以使用 browserslist 自动配置支持的浏览器。
¥Starting with v1.1.10, you can now use browserslist to automatically configure supported browsers.
用法
¥Usage
{
"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 查询 (有限制) :
¥Describes the environments you support/target for your project. This can either be a browserslist-compatible query (with limitations) :
{
"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
如果未指定 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 中的.browserslistrc或browserslist字段。如果你的构建系统不在项目的根目录中,这可能很有用。¥
pathspecifies the directory to load thebrowserslistmodule and any browserslist configuration files. For example,.browserslistrcorbrowserslistfield in package.json. This can be useful if your build system isn’t in the root of your project.
mode
-
string,默认为undefined。¥
string, defaults toundefined. -
可能的值:
usage、entry、undefined(这与 Babel 中的useBuiltIns匹配)¥Possible values:
usage,entry,undefined(this matchesuseBuiltInsfrom Babel)
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:
{
"env": {
"skip": ["core-js/modules/foo"]
}
}coreJs
-
string,默认为undefined。¥
string, defaults toundefined. -
coreJs指定要使用的core-js版本,可以是 swc 支持的任何 core-js 版本。例如,"3.22"。¥
coreJsspecifies the version ofcore-jsto 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 tofalse. -
dynamicImport:(布尔值)默认为false。¥
dynamicImport: (boolean) defaults tofalse. -
loose:(布尔值)默认为false。为任何允许它们的插件启用 松散变换 。¥
loose: (boolean) defaults tofalse. Enable loose transformations for any plugins that allow them. -
include:(string[]) 可以是core-js模块 (es.math.sign) 或 SWC 通行证 (transform-spread)。¥
include: (string[]) can be acore-jsmodule (es.math.sign) or an SWC pass (transform-spread). -
exclude:(string[]) 可以是core-js模块 (es.math.sign) 或 SWC 通行证 (transform-spread)。¥
exclude: (string[]) can be acore-jsmodule (es.math.sign) or an SWC pass (transform-spread). -
shippedProposals:(布尔值)默认为false。¥
shippedProposals: (boolean) defaults tofalse. -
forceAllTransforms:(布尔值)默认为false。启用所有可能的转换。¥
forceAllTransforms: (boolean) defaults tofalse. Enable all possible transforms.